diff options
author | Sage Weil <sage@newdream.net> | 2013-02-17 21:52:55 -0800 |
---|---|---|
committer | Sage Weil <sage@newdream.net> | 2013-02-17 21:52:55 -0800 |
commit | 42fba772c3c0e2396124a9d6ec39297dd9af4cc9 (patch) | |
tree | f1306cc3ab0876cfadb2a9b60c203e79421ea2ba | |
parent | 290a352c3f9e241deac562e980ac8c6a74033ba6 (diff) | |
parent | ad6655e976916d3b62e0c91fd469eeb49fe7da3e (diff) | |
download | ceph-42fba772c3c0e2396124a9d6ec39297dd9af4cc9.tar.gz |
Merge pull request #64 from dalgaaf/wip-bobtail-memleaks
cherry-pick some memleak fixes from master to bobtail
-rw-r--r-- | src/client/SyntheticClient.cc | 15 | ||||
-rw-r--r-- | src/common/fiemap.cc | 9 | ||||
-rw-r--r-- | src/os/FileStore.cc | 7 | ||||
-rw-r--r-- | src/rgw/rgw_rest.cc | 4 | ||||
-rw-r--r-- | src/rgw/rgw_xml.cc | 11 |
5 files changed, 35 insertions, 11 deletions
diff --git a/src/client/SyntheticClient.cc b/src/client/SyntheticClient.cc index b2a936f55ac..30e31072f2b 100644 --- a/src/client/SyntheticClient.cc +++ b/src/client/SyntheticClient.cc @@ -1977,7 +1977,10 @@ int SyntheticClient::write_file(string& fn, int size, loff_t wrsize) // size i int fd = client->open(fn.c_str(), O_RDWR|O_CREAT); dout(5) << "writing to " << fn << " fd " << fd << dendl; - if (fd < 0) return fd; + if (fd < 0) { + delete[] buf; + return fd; + } utime_t from = ceph_clock_now(g_ceph_context); utime_t start = from; @@ -2037,7 +2040,10 @@ int SyntheticClient::write_fd(int fd, int size, int wrsize) // size is in MB, uint64_t chunks = (uint64_t)size * (uint64_t)(1024*1024) / (uint64_t)wrsize; //dout(5) << "SyntheticClient::write_fd: writing to fd " << fd << dendl; - if (fd < 0) return fd; + if (fd < 0) { + delete[] buf; + return fd; + } for (unsigned i=0; i<chunks; i++) { if (time_to_stop()) { @@ -2087,7 +2093,10 @@ int SyntheticClient::read_file(const std::string& fn, int size, int fd = client->open(fn.c_str(), O_RDONLY); dout(5) << "reading from " << fn << " fd " << fd << dendl; - if (fd < 0) return fd; + if (fd < 0) { + delete[] buf; + return fd; + } utime_t from = ceph_clock_now(g_ceph_context); utime_t start = from; 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); 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); diff --git a/src/rgw/rgw_rest.cc b/src/rgw/rgw_rest.cc index 72aab14c522..ab3927e7a62 100644 --- a/src/rgw/rgw_rest.cc +++ b/src/rgw/rgw_rest.cc @@ -684,8 +684,10 @@ static int read_all_chunked_input(req_state *s, char **pdata, int *plen) int read_len = 0, len = 0; do { int r = s->cio->read(data + len, need_to_read, &read_len); - if (r < 0) + if (r < 0) { + free(data); return r; + } len += read_len; diff --git a/src/rgw/rgw_xml.cc b/src/rgw/rgw_xml.cc index 4347b06115c..eee69d026ba 100644 --- a/src/rgw/rgw_xml.cc +++ b/src/rgw/rgw_xml.cc @@ -209,9 +209,16 @@ bool RGWXMLParser::init() bool RGWXMLParser::parse(const char *_buf, int len, int done) { int pos = buf_len; - buf = (char *)realloc(buf, buf_len + len); - if (!buf) + char *tmp_buf; + tmp_buf = (char *)realloc(buf, buf_len + len); + if (tmp_buf == NULL){ + free(buf); + buf = NULL; return false; + } else { + buf = tmp_buf; + } + memcpy(&buf[buf_len], _buf, len); buf_len += len; |