Commit 4b28b03dbbc0a95ce305a3062a8ddc34d395884b
1 parent
ff76415a1b
Exists in
smarc_8mm-imx_v2018.03_4.14.98_2.0.0_ga
and in
4 other branches
MA-14293 [coverity] imx8: Fix double free issue
Fix coverity issue CID 3298992: Double free (USE_AFTER_FREE) double_free: Calling free frees pointer rsrc_data which has already been freed. Check the rsrc_data buffer before free to avoid free NULL pointer. Change-Id: I781e87667a5d3bbe25ec12fbae8e3958d9b29244 Signed-off-by: Luo Ji <ji.luo@nxp.com>
Showing 1 changed file with 5 additions and 2 deletions Side-by-side Diff
arch/arm/mach-imx/imx8/partition.c
... | ... | @@ -170,7 +170,8 @@ |
170 | 170 | pad_data = kmalloc(pad_size, __GFP_ZERO); |
171 | 171 | if (!pad_data) { |
172 | 172 | debug("No mem\n"); |
173 | - free(rsrc_data); | |
173 | + if (rsrc_data != NULL) | |
174 | + free(rsrc_data); | |
174 | 175 | return CMD_RET_FAILURE; |
175 | 176 | } |
176 | 177 | if (fdtdec_get_int_array(fdt, subnode, "pads", |
177 | 178 | |
... | ... | @@ -235,8 +236,10 @@ |
235 | 236 | free_data: |
236 | 237 | if (pad_size > 0) |
237 | 238 | free(pad_data); |
238 | - if (rsrc_size > 0) | |
239 | + if (rsrc_size > 0) { | |
239 | 240 | free(rsrc_data); |
241 | + rsrc_data = NULL; | |
242 | + } | |
240 | 243 | } |
241 | 244 | |
242 | 245 | } |