diff options
author | Danny Al-Gaaf <danny.al-gaaf@bisect.de> | 2013-02-08 16:54:33 +0100 |
---|---|---|
committer | Danny Al-Gaaf <danny.al-gaaf@bisect.de> | 2013-02-16 18:38:47 +0100 |
commit | b0c6be95b03d9f3dd2badcdcff359ae7bc9684f4 (patch) | |
tree | e4ae4f82c722d0af512bedbf8035648f354709fe | |
parent | f3e5cedbc11005701ac0a8e70909a6372cd2fe6f (diff) | |
download | ceph-b0c6be95b03d9f3dd2badcdcff359ae7bc9684f4.tar.gz |
os/FileStore.cc: fix realloc memory leak in error case
Fix error from cppcheck:
[src/os/FileStore.cc:512]: (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 c92a0f552587a232f66620170660d6b2ab6fb3a5)
-rw-r--r-- | src/os/FileStore.cc | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/src/os/FileStore.cc b/src/os/FileStore.cc index 1bab9c3c36d..44f3b571960 100644 --- a/src/os/FileStore.cc +++ b/src/os/FileStore.cc @@ -490,6 +490,7 @@ bool parse_attrname(char **name) static int do_fiemap(int fd, off_t start, size_t len, struct fiemap **pfiemap) { struct fiemap *fiemap = NULL; + struct fiemap *_realloc_fiemap = NULL; int size; int ret; @@ -509,11 +510,13 @@ static int do_fiemap(int fd, off_t start, size_t len, struct fiemap **pfiemap) size = sizeof(struct fiemap_extent) * (fiemap->fm_mapped_extents); - fiemap = (struct fiemap *)realloc(fiemap, sizeof(struct fiemap) + + _realloc_fiemap = (struct fiemap *)realloc(fiemap, sizeof(struct fiemap) + size); - if (!fiemap) { + if (!_realloc_fiemap) { ret = -ENOMEM; goto done_err; + } else { + fiemap = _realloc_fiemap; } memset(fiemap->fm_extents, 0, size); |