Skip to content

Commit c92d47e

Browse files
dalgaafliewegas
authored andcommitted
libradosstriper/striping.cc: fix strdup memory leaks
Fix memory leak caused by using std::string to hold result of strdup call returned from getObjName(). Fix for Coverity issues: CID 1221525 (#1 of 1): Resource leak (RESOURCE_LEAK) leaked_storage: Failing to save or free storage allocated by this->getObjName(soid, 0UL) leaks it. CID 1221526 (1-3 of 3): Resource leak (RESOURCE_LEAK) leaked_storage: Failing to save or free storage allocated by this->getObjName(soid, *) leaks it. Signed-off-by: Danny Al-Gaaf <danny.al-gaaf@bisect.de>
1 parent be674c5 commit c92d47e

1 file changed

Lines changed: 10 additions & 4 deletions

File tree

src/test/libradosstriper/striping.cc

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2+
// vim: ts=8 sw=2 smarttab
13
#include "include/rados/librados.h"
24
#include "include/rados/librados.hpp"
35
#include "include/radosstriper/libradosstriper.h"
@@ -36,7 +38,7 @@ class StriperTestRT : public StriperTestParam {
3638
{
3739
// checking first object's rados xattrs
3840
bufferlist xattrbl;
39-
std::string firstOid = getObjName(soid, 0);
41+
char* firstOid = getObjName(soid, 0);
4042
ASSERT_LT(0, ioctx.getxattr(firstOid, "striper.layout.stripe_unit", xattrbl));
4143
std::string s_xattr(xattrbl.c_str(), xattrbl.length()); // adds 0 byte at the end
4244
uint64_t stripe_unit = strtoll(s_xattr.c_str(), NULL, 10);
@@ -83,7 +85,7 @@ class StriperTestRT : public StriperTestParam {
8385
}
8486
bufferlist stripe_data;
8587
// check object content
86-
std::string oid = getObjName(soid, object_nb);
88+
char* oid = getObjName(soid, object_nb);
8789
int rc = ioctx.read(oid, stripe_data, len, start);
8890
if (actual_size_if_sparse < size and
8991
(actual_size_if_sparse+stripe_unit-1)/stripe_unit <= stripe_nb) {
@@ -100,6 +102,7 @@ class StriperTestRT : public StriperTestParam {
100102
original_data.substr_of(bl, stripe_nb*stripe_unit, len);
101103
ASSERT_EQ(0, memcmp(original_data.c_str(), stripe_data.c_str(), len));
102104
}
105+
free(oid);
103106
}
104107
// checking rados object sizes; we go object by object
105108
uint64_t nb_full_object_sets = nb_stripes_in_object / stripe_per_objectset;
@@ -109,7 +112,7 @@ class StriperTestRT : public StriperTestParam {
109112
for (uint64_t object_nb = 0; object_nb < nb_objects; object_nb++) {
110113
uint64_t rados_size;
111114
time_t mtime;
112-
std::string oid = getObjName(soid, object_nb);
115+
char* oid = getObjName(soid, object_nb);
113116
uint64_t nb_full_object_set = object_nb / stripe_count;
114117
uint64_t object_index_in_set = object_nb % stripe_count;
115118
uint64_t object_start_stripe = nb_full_object_set * stripe_per_objectset + object_index_in_set;
@@ -133,12 +136,15 @@ class StriperTestRT : public StriperTestParam {
133136
}
134137
ASSERT_EQ(len, rados_size);
135138
}
139+
free(oid);
136140
}
137141
// check we do not have an extra object behind
138142
uint64_t rados_size;
139143
time_t mtime;
140-
std::string oid = getObjName(soid, nb_objects);
144+
char* oid = getObjName(soid, nb_objects);
141145
ASSERT_EQ(-ENOENT, ioctx.stat(oid, &rados_size, &mtime));
146+
free(oid);
147+
free(firstOid);
142148
}
143149
};
144150

0 commit comments

Comments
 (0)