diff options
author | Sage Weil <sage@inktank.com> | 2013-02-10 18:04:02 -0800 |
---|---|---|
committer | Sage Weil <sage@inktank.com> | 2013-02-10 18:04:02 -0800 |
commit | 2919574531f1d6dee0b7eab9cc5c4b9a9b7f2a82 (patch) | |
tree | ad3d0ba33cbb600a4b6f50b2c147daa02b658f9e | |
parent | abc80ffc5b1aab3915c049701ab85c57fe93d550 (diff) | |
parent | 89df090e04ef9fc5aae29122df106b0347786fab (diff) | |
download | ceph-2919574531f1d6dee0b7eab9cc5c4b9a9b7f2a82.tar.gz |
Merge remote-tracking branch 'danny/wip-da-sca-memleaks'
Reviewed-by: Sage Weil <sage@inktank.com>
-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 | ||||
-rw-r--r-- | wireshark/ceph/packet-ceph.c | 19 |
6 files changed, 49 insertions, 16 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; diff --git a/wireshark/ceph/packet-ceph.c b/wireshark/ceph/packet-ceph.c index 5d2c702251a..2a4e31fad3f 100644 --- a/wireshark/ceph/packet-ceph.c +++ b/wireshark/ceph/packet-ceph.c @@ -209,8 +209,8 @@ static gint ett_ceph_footer = -1; const char *ceph_cap_op_name(int op) { - char* plop = malloc(16*sizeof(char)); - sprintf(plop,"%i",op); + char* plop; + switch (op) { case CEPH_CAP_OP_GRANT: return "grant"; case CEPH_CAP_OP_REVOKE: return "revoke"; @@ -226,13 +226,17 @@ const char *ceph_cap_op_name(int op) case CEPH_CAP_OP_RELEASE: return "release"; case CEPH_CAP_OP_RENEW: return "renew"; } + + plop = malloc(16*sizeof(char)); + sprintf(plop,"%i",op); + return plop; } const char *ceph_mds_op_name(int op) { - char* plop = malloc(16*sizeof(char)); - sprintf(plop,"%i",op); + char* plop; + switch (op) { case CEPH_MDS_OP_LOOKUP: return "lookup"; case CEPH_MDS_OP_LOOKUPHASH: return "lookuphash"; @@ -261,6 +265,10 @@ const char *ceph_mds_op_name(int op) case CEPH_MDS_OP_SETFILELOCK: return "setfilelock"; case CEPH_MDS_OP_GETFILELOCK: return "getfilelock"; } + + plop = malloc(16*sizeof(char)); + printf(plop,"%i",op); + return plop; } @@ -533,13 +541,14 @@ static guint32 dissect_ceph_fsid(tvbuff_t *tvb, proto_tree *tree, guint32 offset fsid_dec = malloc(4*sizeof(guint32)); fsid = *(struct ceph_fsid *)tvb_get_ptr(tvb, offset, sizeof(struct ceph_fsid)); memcpy(fsid_dec,fsid.fsid,4*sizeof(guint32)); - proto_tree_add_text(tree, tvb, offset,sizeof(struct ceph_fsid), "fsid: %x-%x-%x-%x", + proto_tree_add_text(tree, tvb, offset, sizeof(struct ceph_fsid), "fsid: %x-%x-%x-%x", ntohl(fsid_dec[0]), ntohl(fsid_dec[1]), ntohl(fsid_dec[2]), ntohl(fsid_dec[3]) ); offset += sizeof(struct ceph_fsid); + free (fsid_dec); return offset; } |