summaryrefslogtreecommitdiff
path: root/include/share
diff options
context:
space:
mode:
authorlutianxiong <lutianxiong@huawei.com>2020-06-04 14:58:06 +0800
committerMartijn van Beurden <mvanb1@gmail.com>2022-08-20 16:03:53 +0200
commitb715d7b9fe90f5b411ae1c159553c7c287f0789a (patch)
treeaa5d203d6971d45d931edb7df669f1f6adbaae49 /include/share
parent35306a812bab3de099db1539ddae546ee3ffebed (diff)
downloadflac-b715d7b9fe90f5b411ae1c159553c7c287f0789a.tar.gz
fix potential memleak
Diffstat (limited to 'include/share')
-rw-r--r--include/share/alloc.h8
1 files changed, 6 insertions, 2 deletions
diff --git a/include/share/alloc.h b/include/share/alloc.h
index edd3a79e..9b53b010 100644
--- a/include/share/alloc.h
+++ b/include/share/alloc.h
@@ -200,8 +200,10 @@ static inline void *safe_realloc_mul_2op_(void *ptr, size_t size1, size_t size2)
{
if(!size1 || !size2)
return realloc(ptr, 0); /* preserve POSIX realloc(ptr, 0) semantics */
- if(size1 > SIZE_MAX / size2)
+ if(size1 > SIZE_MAX / size2) {
+ free(ptr);
return 0;
+ }
return safe_realloc_(ptr, size1*size2);
}
@@ -211,8 +213,10 @@ static inline void *safe_realloc_muladd2_(void *ptr, size_t size1, size_t size2,
if(!size1 || (!size2 && !size3))
return realloc(ptr, 0); /* preserve POSIX realloc(ptr, 0) semantics */
size2 += size3;
- if(size2 < size3)
+ if(size2 < size3) {
+ free(ptr);
return 0;
+ }
return safe_realloc_mul_2op_(ptr, size1, size2);
}