You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by bc...@apache.org on 2016/10/27 00:03:07 UTC
[trafficserver] branch master updated: TS-4956: Memory leaks in
hostdb test
This is an automated email from the ASF dual-hosted git repository.
bcall pushed a commit to branch master
in repository https://git-dual.apache.org/repos/asf/trafficserver.git
The following commit(s) were added to refs/heads/master by this push:
new 0bd0428 TS-4956: Memory leaks in hostdb test
0bd0428 is described below
commit 0bd042856465420bb5ebe8db7412ba649988e891
Author: Bryan Call <bc...@apache.org>
AuthorDate: Tue Oct 11 12:58:01 2016 -0700
TS-4956: Memory leaks in hostdb test
---
iocore/hostdb/P_RefCountCache.h | 5 ++++-
iocore/hostdb/test_RefCountCache.cc | 36 +++++++++++++++++++++++++++++++++---
2 files changed, 37 insertions(+), 4 deletions(-)
diff --git a/iocore/hostdb/P_RefCountCache.h b/iocore/hostdb/P_RefCountCache.h
index 833952d..563cdfb 100644
--- a/iocore/hostdb/P_RefCountCache.h
+++ b/iocore/hostdb/P_RefCountCache.h
@@ -444,7 +444,10 @@ RefCountCache<C>::RefCountCache(unsigned int num_partitions, int size, int items
// Deconstruct the class
template <class C> RefCountCache<C>::~RefCountCache()
{
- delete this->partitions;
+ for (unsigned int i = 0; i < num_partitions; i++) {
+ delete this->partitions[i];
+ }
+ num_partitions = 0;
}
template <class C>
diff --git a/iocore/hostdb/test_RefCountCache.cc b/iocore/hostdb/test_RefCountCache.cc
index 05e50ae..c6a3a80 100644
--- a/iocore/hostdb/test_RefCountCache.cc
+++ b/iocore/hostdb/test_RefCountCache.cc
@@ -26,6 +26,7 @@
#include <I_EventSystem.h>
#include <ts/I_Layout.h>
#include <diags.i>
+#include <set>
// TODO: add tests with expiry_time
@@ -34,6 +35,7 @@ class ExampleStruct : public RefCountObj
public:
int idx;
int name_offset; // pointer addr to name
+ static std::set<ExampleStruct *> items_freed;
// Return the char* to the name (TODO: cleaner interface??)
char *
@@ -48,11 +50,20 @@ public:
return new (malloc(sizeof(ExampleStruct) + size)) ExampleStruct();
}
- // To mark it as "deleted" (so its easy to check) we'll just mark the idx as -1
+ static void
+ dealloc(ExampleStruct *e)
+ {
+ e->~ExampleStruct();
+ ::free(e);
+ }
+
+ // Really free the memory, we can use asan leak detection to verify it was freed
void
free()
{
this->idx = -1;
+ items_freed.insert(this);
+ printf("freeing: %p items_freed.size(): %zd\n", this, items_freed.size());
}
static ExampleStruct *
@@ -70,6 +81,8 @@ public:
}
};
+std::set<ExampleStruct *> ExampleStruct::items_freed;
+
void
fillCache(RefCountCache<ExampleStruct> *cache, int start, int end)
{
@@ -166,6 +179,8 @@ testRefcounting()
ret |= tmpAfter.get()->idx != 1;
printf("ret=%d ref=%d\n", ret, tmp->refcount());
+ delete cache;
+
return ret;
}
@@ -189,7 +204,7 @@ testclear()
}
int
-main()
+test()
{
// Initialize IOBufAllocator
RecModeT mode_type = RECM_STAND_ALONE;
@@ -264,7 +279,22 @@ main()
// printf("Sync return: %d\n", cache->sync_all());
printf("TestRun: %d\n", ret);
- exit(ret);
+
+ delete cache;
+
+ return ret;
+}
+
+int
+main()
+{
+ int ret = test();
+
+ for (const auto item : ExampleStruct::items_freed) {
+ printf("really freeing: %p\n", item);
+ ExampleStruct::dealloc(item);
+ }
+ ExampleStruct::items_freed.clear();
return ret;
}
--
To stop receiving notification emails like this one, please contact
['"commits@trafficserver.apache.org" <co...@trafficserver.apache.org>'].