common: Fix memory leak and incorrect comparison
PATCH 1/1 common: Fix memory leak and incorrect comparison
Changing the order of actions: the input argument is checked before memory is allocated.
The input argument n is of type size_t and cannot take negative values, so the comparison has been fixed.
Signed-off-by Maks Mishin <[email protected]>
--- common/dlmalloc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
common/dlmalloc.c +2 -2
@@ -2093,6 +2093,8 @@ Void_t* cALLOc_impl(n, elem_size) size_t n; size_t elem_size;mchunkptr p;INTERNAL_SIZE_T csz; +if ((long )n <=0 )return NULL ; +INTERNAL_SIZE_T sz = n * elem_size;/* check if expand_top called, in which case don't need to clear */
@@ -2104,8 +2106,6 @@ Void_t* cALLOc_impl(n, elem_size) size_t n; size_t elem_size;#endif Void_t * mem =mALLOc_impl (sz); -if ((long )n <0 )return NULL ; -if (mem ==NULL )return NULL ;else
Signature · 1 line
2.34.1
Quoted 10 lines · Maks Mishin
Changing the order of actions: the input argument is checked before memory is allocated.
The input argument
nis of typesize_tand cannot take negative values, so the comparison has been fixed.Signed-off-by Maks Mishin <[email protected]>--- common/dlmalloc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
This introduces runtime failures:
https://source.denx.de/u-boot/u-boot/-/jobs/1018726
Signature · 1 line
Tom