Commit 74fe0a0
committed
qdl: fix resource leaks in programmer image decoding
decode_programmer_archive() allocates images[id].ptr (via malloc)
and images[id].name (via strdup) while iterating CPIO entries. If
a later entry fails validation, all previously allocated entries
leak because the function returns -1 immediately.
The same leak exists in decode_sahara_config() and its callers:
decode_programmer() doesn't clean up partially-populated images on
error, and qdl_flash() never frees the sahara_images array even on
the normal exit path.
Rather than restructuring the parser loop with break/cleanup logic,
fix this at the ownership level:
- Introduce sahara_images_free() as a reusable cleanup helper.
free(NULL) is well-defined per C standard, so no NULL guards
are needed before calling free().
- Drop 'const' from sahara_image.name: the struct always owns the
allocation (via strdup), so const is misleading and forces casts
when freeing. This follows the principle that the owner of a
heap allocation should hold a non-const pointer to it.
- Call sahara_images_free() in decode_programmer() error paths and
in qdl_flash() cleanup, keeping decode_programmer_archive()
itself simple with its existing early returns.
Signed-off-by: Igor Opaniuk <igor.opaniuk@oss.qualcomm.com>1 parent 38ff756 commit 74fe0a0
3 files changed
+19
-2
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
395 | 395 | | |
396 | 396 | | |
397 | 397 | | |
398 | | - | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
399 | 403 | | |
400 | 404 | | |
401 | 405 | | |
| |||
747 | 751 | | |
748 | 752 | | |
749 | 753 | | |
| 754 | + | |
| 755 | + | |
| 756 | + | |
750 | 757 | | |
751 | 758 | | |
752 | 759 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
79 | 79 | | |
80 | 80 | | |
81 | 81 | | |
82 | | - | |
| 82 | + | |
83 | 83 | | |
84 | 84 | | |
85 | 85 | | |
| |||
113 | 113 | | |
114 | 114 | | |
115 | 115 | | |
| 116 | + | |
116 | 117 | | |
117 | 118 | | |
118 | 119 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
266 | 266 | | |
267 | 267 | | |
268 | 268 | | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
0 commit comments