mirror of
https://github.com/AFLplusplus/AFLplusplus.git
synced 2025-06-18 12:48:06 +00:00
fix two exotic mem leaks detected by cppcheck
This commit is contained in:
@ -636,7 +636,7 @@ struct afl_alloc_buf {
|
|||||||
|
|
||||||
#define AFL_ALLOC_SIZE_OFFSET (offsetof(struct afl_alloc_buf, buf))
|
#define AFL_ALLOC_SIZE_OFFSET (offsetof(struct afl_alloc_buf, buf))
|
||||||
|
|
||||||
/* Returs the container element to this ptr */
|
/* Returns the container element to this ptr */
|
||||||
static inline struct afl_alloc_buf *afl_alloc_bufptr(void *buf) {
|
static inline struct afl_alloc_buf *afl_alloc_bufptr(void *buf) {
|
||||||
|
|
||||||
return (struct afl_alloc_buf *)((u8 *)buf - AFL_ALLOC_SIZE_OFFSET);
|
return (struct afl_alloc_buf *)((u8 *)buf - AFL_ALLOC_SIZE_OFFSET);
|
||||||
@ -694,14 +694,20 @@ static inline void *afl_realloc(void **buf, size_t size_needed) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* alloc */
|
/* alloc */
|
||||||
new_buf = (struct afl_alloc_buf *)realloc(new_buf, next_size);
|
struct afl_alloc_buf *newer_buf = (struct afl_alloc_buf *)realloc(new_buf, next_size);
|
||||||
if (unlikely(!new_buf)) {
|
if (unlikely(!newer_buf)) {
|
||||||
|
|
||||||
|
free(new_buf); // avoid a leak
|
||||||
*buf = NULL;
|
*buf = NULL;
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
new_buf = newer_buf;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
new_buf->complete_size = next_size;
|
new_buf->complete_size = next_size;
|
||||||
*buf = (void *)(new_buf->buf);
|
*buf = (void *)(new_buf->buf);
|
||||||
return *buf;
|
return *buf;
|
||||||
@ -730,12 +736,17 @@ static inline void *afl_realloc_exact(void **buf, size_t size_needed) {
|
|||||||
if (unlikely(current_size == size_needed)) { return *buf; }
|
if (unlikely(current_size == size_needed)) { return *buf; }
|
||||||
|
|
||||||
/* alloc */
|
/* alloc */
|
||||||
new_buf = (struct afl_alloc_buf *)realloc(new_buf, size_needed);
|
struct afl_alloc_buf *newer_buf = (struct afl_alloc_buf *)realloc(new_buf, size_needed);
|
||||||
if (unlikely(!new_buf)) {
|
if (unlikely(!newer_buf)) {
|
||||||
|
|
||||||
|
free(new_buf); // avoid a leak
|
||||||
*buf = NULL;
|
*buf = NULL;
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
new_buf = newer_buf;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
new_buf->complete_size = size_needed;
|
new_buf->complete_size = size_needed;
|
||||||
|
Reference in New Issue
Block a user