-
Notifications
You must be signed in to change notification settings - Fork 157
Fix samples memory leak and cleanup issues #137
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix samples memory leak and cleanup issues #137
Conversation
Fix memory leaks and cleanup logic in the following sample programs: - samples/core/binaries - samples/core/blur - samples/core/reduce - samples/core/saxpy - samples/core/multi-device - samples/extensions/khr/externalmemory Also fix minor logic and error-handling inconsistencies such as: - Ensuring proper release of cl_event objects - Correct ordering of Vulkan cleanup calls - Improved version string checks and CLI option allocation Signed-off-by: Xin Jin <xin.jin@arm.com>
|
I'll do a more thorough review once the CLA is signed, but I can confirm that I do not see any OpenCL object leaks after these changes (verified with the OpenCL Intercept Layer and LeakChecking). Thanks! |
|
thanks @bashbaug , I just signed the CLA. |
bashbaug
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! LGTM.
Fix a use-after-free warning reported by GCC:
error: pointer 'dev_version' may be used after 'free'
else if (opencl_version_contains(dev_version, "2."))
Previously, dev_version was freed immediately after checking for
OpenCL 1.0/1.1, but later reused for determining whether to add -cl-std
compiler options. This triggered -Werror=use-after-free under GCC with
strict diagnostics.
This patch:
- Defers free(dev_version) to a new 'ver:' cleanup label to avoid
premature free.
- Replaces raw malloc/free with MEM_CHECK for safety and consistency.
- Adds snprintf-based -cl-std option handling with bounds checking.
- Moves compiler_options logic earlier to avoid stale pointer usage.
- Removes old compiler_options block near clBuildProgram.
The refactoring ensures correctness, eliminates UB, and prepares for
cleaner version-based behavior in the future.
Signed-off-by: Xin Jin <xin.jin@arm.com>
To address review comment Signed-off-by: Xin Jin <xin.jin@arm.com>
bashbaug
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! LGTM, aside from one nitpick.
Calling free() on a NULL pointer is well-defined and has no effect. This simplifies the code by removing an unnecessary conditional. Signed-off-by: Xin Jin <xin.jin@arm.com>
|
I filed an issue for the macOS CI failures, which seem unrelated to your changes: #144. I'm going to merge these changes as-is. Thank you again for the fixes! |
Fix memory leaks and cleanup logic in the following sample programs:
Also fix minor logic and error-handling inconsistencies such as: