diff options
author | Danny Al-Gaaf <danny.al-gaaf@bisect.de> | 2013-02-08 16:49:36 +0100 |
---|---|---|
committer | Danny Al-Gaaf <danny.al-gaaf@bisect.de> | 2013-02-16 18:38:19 +0100 |
commit | f3e5cedbc11005701ac0a8e70909a6372cd2fe6f (patch) | |
tree | 571a5b2da57d907bffb3c0e84a2ad4173df4084c | |
parent | 290a352c3f9e241deac562e980ac8c6a74033ba6 (diff) | |
download | ceph-f3e5cedbc11005701ac0a8e70909a6372cd2fe6f.tar.gz |
common/fiemap.cc: fix realloc memory leak
Fix error from cppcheck:
[src/common/fiemap.cc:73]: (error) Common realloc mistake: 'fiemap'
nulled but not freed upon failure
Signed-off-by: Danny Al-Gaaf <danny.al-gaaf@bisect.de>
(cherry picked from commit f26f1470e7af36fa1eb8dc59c8a7c62c3c3a22ba)
-rw-r--r-- | src/common/fiemap.cc | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/src/common/fiemap.cc b/src/common/fiemap.cc index 0df12d6e8fd..a1d5fbe9396 100644 --- a/src/common/fiemap.cc +++ b/src/common/fiemap.cc @@ -40,6 +40,7 @@ struct fiemap *read_fiemap(int fd) { struct fiemap *fiemap; + struct fiemap *_realloc_fiemap = NULL; int extents_size; int r; @@ -62,18 +63,20 @@ struct fiemap *read_fiemap(int fd) } if (!fiemap->fm_mapped_extents) { - free(fiemap); - return NULL; + goto done_err; } /* Read in the extents */ extents_size = sizeof(struct fiemap_extent) * (fiemap->fm_mapped_extents); /* Resize fiemap to allow us to read in the extents */ - if ((fiemap = (struct fiemap*)realloc(fiemap,sizeof(struct fiemap) + + + if ((_realloc_fiemap = (struct fiemap*)realloc(fiemap,sizeof(struct fiemap) + extents_size)) == NULL) { fprintf(stderr, "Out of memory allocating fiemap\n"); goto done_err; + } else { + fiemap = _realloc_fiemap; } memset(fiemap->fm_extents, 0, extents_size); |