Commit 6f25f5d
authored
Fix samples memory leak and cleanup issues (#137)
* Fix samples memory leak and cleanup issues
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>
* Fix use-after-free on dev_version in version logic
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>
* Replace label endl with end
To address review comment
Signed-off-by: Xin Jin <xin.jin@arm.com>
* Remove redundant NULL check before free(dev_version)
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>
---------
Signed-off-by: Xin Jin <xin.jin@arm.com>1 parent 8cd6194 commit 6f25f5d
7 files changed
Lines changed: 143 additions & 81 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
258 | 258 | | |
259 | 259 | | |
260 | 260 | | |
261 | | - | |
262 | 261 | | |
263 | 262 | | |
264 | 263 | | |
| 264 | + | |
265 | 265 | | |
266 | 266 | | |
267 | 267 | | |
268 | | - | |
| 268 | + | |
269 | 269 | | |
270 | 270 | | |
271 | 271 | | |
272 | 272 | | |
273 | 273 | | |
274 | 274 | | |
275 | | - | |
| 275 | + | |
276 | 276 | | |
277 | 277 | | |
278 | 278 | | |
| |||
298 | 298 | | |
299 | 299 | | |
300 | 300 | | |
| 301 | + | |
| 302 | + | |
301 | 303 | | |
302 | 304 | | |
303 | 305 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
359 | 359 | | |
360 | 360 | | |
361 | 361 | | |
362 | | - | |
| 362 | + | |
363 | 363 | | |
364 | 364 | | |
365 | 365 | | |
366 | 366 | | |
367 | 367 | | |
368 | | - | |
| 368 | + | |
369 | 369 | | |
370 | 370 | | |
371 | 371 | | |
372 | 372 | | |
373 | | - | |
374 | | - | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
375 | 376 | | |
376 | 377 | | |
377 | 378 | | |
| |||
417 | 418 | | |
418 | 419 | | |
419 | 420 | | |
420 | | - | |
421 | | - | |
| 421 | + | |
| 422 | + | |
422 | 423 | | |
423 | 424 | | |
424 | 425 | | |
425 | 426 | | |
426 | 427 | | |
427 | | - | |
| 428 | + | |
428 | 429 | | |
429 | 430 | | |
430 | 431 | | |
431 | 432 | | |
432 | | - | |
433 | | - | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
434 | 438 | | |
435 | 439 | | |
436 | 440 | | |
| |||
531 | 535 | | |
532 | 536 | | |
533 | 537 | | |
534 | | - | |
535 | | - | |
| 538 | + | |
| 539 | + | |
536 | 540 | | |
537 | 541 | | |
538 | 542 | | |
539 | 543 | | |
540 | 544 | | |
541 | | - | |
| 545 | + | |
542 | 546 | | |
543 | 547 | | |
544 | 548 | | |
545 | 549 | | |
546 | | - | |
547 | | - | |
| 550 | + | |
| 551 | + | |
| 552 | + | |
| 553 | + | |
| 554 | + | |
548 | 555 | | |
549 | 556 | | |
550 | 557 | | |
| |||
620 | 627 | | |
621 | 628 | | |
622 | 629 | | |
623 | | - | |
624 | | - | |
| 630 | + | |
| 631 | + | |
625 | 632 | | |
626 | 633 | | |
627 | 634 | | |
628 | 635 | | |
629 | 636 | | |
630 | | - | |
| 637 | + | |
631 | 638 | | |
632 | 639 | | |
633 | 640 | | |
634 | 641 | | |
635 | | - | |
| 642 | + | |
636 | 643 | | |
637 | 644 | | |
| 645 | + | |
| 646 | + | |
| 647 | + | |
| 648 | + | |
638 | 649 | | |
639 | 650 | | |
640 | 651 | | |
| |||
685 | 696 | | |
686 | 697 | | |
687 | 698 | | |
688 | | - | |
689 | | - | |
| 699 | + | |
| 700 | + | |
690 | 701 | | |
691 | 702 | | |
692 | 703 | | |
693 | 704 | | |
694 | 705 | | |
695 | | - | |
| 706 | + | |
696 | 707 | | |
697 | 708 | | |
698 | 709 | | |
699 | 710 | | |
700 | | - | |
701 | | - | |
| 711 | + | |
| 712 | + | |
| 713 | + | |
| 714 | + | |
| 715 | + | |
702 | 716 | | |
703 | 717 | | |
704 | 718 | | |
| |||
801 | 815 | | |
802 | 816 | | |
803 | 817 | | |
804 | | - | |
805 | | - | |
| 818 | + | |
| 819 | + | |
806 | 820 | | |
807 | 821 | | |
808 | 822 | | |
809 | 823 | | |
810 | 824 | | |
811 | | - | |
| 825 | + | |
812 | 826 | | |
813 | 827 | | |
814 | 828 | | |
815 | 829 | | |
816 | | - | |
817 | | - | |
| 830 | + | |
| 831 | + | |
| 832 | + | |
| 833 | + | |
| 834 | + | |
818 | 835 | | |
819 | 836 | | |
820 | 837 | | |
| |||
894 | 911 | | |
895 | 912 | | |
896 | 913 | | |
897 | | - | |
898 | | - | |
| 914 | + | |
| 915 | + | |
899 | 916 | | |
900 | 917 | | |
901 | 918 | | |
902 | 919 | | |
903 | 920 | | |
904 | | - | |
| 921 | + | |
905 | 922 | | |
906 | 923 | | |
907 | 924 | | |
908 | 925 | | |
909 | | - | |
| 926 | + | |
910 | 927 | | |
911 | 928 | | |
| 929 | + | |
| 930 | + | |
| 931 | + | |
| 932 | + | |
912 | 933 | | |
913 | 934 | | |
914 | 935 | | |
| |||
1073 | 1094 | | |
1074 | 1095 | | |
1075 | 1096 | | |
1076 | | - | |
| 1097 | + | |
1077 | 1098 | | |
1078 | 1099 | | |
1079 | 1100 | | |
1080 | | - | |
| 1101 | + | |
1081 | 1102 | | |
1082 | 1103 | | |
1083 | 1104 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
208 | 208 | | |
209 | 209 | | |
210 | 210 | | |
211 | | - | |
212 | | - | |
213 | | - | |
214 | | - | |
215 | | - | |
216 | | - | |
217 | 211 | | |
218 | 212 | | |
219 | 213 | | |
| |||
225 | 219 | | |
226 | 220 | | |
227 | 221 | | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
228 | 237 | | |
229 | 238 | | |
230 | 239 | | |
| |||
233 | 242 | | |
234 | 243 | | |
235 | 244 | | |
236 | | - | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
237 | 275 | | |
238 | 276 | | |
239 | 277 | | |
240 | 278 | | |
241 | 279 | | |
242 | 280 | | |
243 | 281 | | |
244 | | - | |
| 282 | + | |
245 | 283 | | |
246 | 284 | | |
247 | 285 | | |
| |||
254 | 292 | | |
255 | 293 | | |
256 | 294 | | |
257 | | - | |
| 295 | + | |
258 | 296 | | |
259 | 297 | | |
260 | 298 | | |
| |||
328 | 366 | | |
329 | 367 | | |
330 | 368 | | |
331 | | - | |
332 | | - | |
333 | | - | |
334 | | - | |
335 | | - | |
336 | | - | |
337 | | - | |
338 | | - | |
339 | | - | |
340 | | - | |
341 | | - | |
342 | | - | |
343 | | - | |
344 | | - | |
345 | 369 | | |
346 | 370 | | |
347 | 371 | | |
| |||
701 | 725 | | |
702 | 726 | | |
703 | 727 | | |
| 728 | + | |
| 729 | + | |
704 | 730 | | |
705 | 731 | | |
706 | 732 | | |
| |||
0 commit comments