Skip to content

Commit f435218

Browse files
committed
Fix memory leaks
1 parent 8b755ae commit f435218

6 files changed

Lines changed: 10 additions & 6 deletions

File tree

src/db.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2703,11 +2703,6 @@ void redisDbPersistentData::prepOverwriteForSnapshot(char *key)
27032703
auto itr = m_pdbSnapshot->find_cached_threadsafe(key);
27042704
if (itr.key() != nullptr)
27052705
{
2706-
if (itr.val()->FExpires()) {
2707-
// Note: I'm sure we could handle this, but its too risky at the moment.
2708-
// There are known bugs doing this with expires
2709-
return;
2710-
}
27112706
sds keyNew = sdsdupshared(itr.key());
27122707
if (dictAdd(m_pdictTombstone, keyNew, (void*)dictHashKey(m_pdict, key)) != DICT_OK)
27132708
sdsfree(keyNew);

src/expire.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,13 +160,17 @@ class expireEntry {
160160

161161
expireEntry &operator=(expireEntry &&e)
162162
{
163+
if (FFat())
164+
delete pfatentry();
163165
s = e.s;
164166
e.s.m_whenAndPtrUnion = 0;
165167
e.s.fFat = false;
166168
return *this;
167169
}
168170

169171
expireEntry &operator=(expireEntry &e) {
172+
if (FFat())
173+
delete pfatentry();
170174
if (e.FFat()) {
171175
s.m_whenAndPtrUnion = reinterpret_cast<long long>(new expireEntryFat(*e.pfatentry()));
172176
s.fFat = true;

src/modules/keydb_modstatsd/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ OBJECT_FILES := modmain.o
44
MODSNAP_CXX_FLAGS := -std=gnu++14
55

66
%.o: %.cpp
7-
$(CXX) -o $@ -c $< $(MODULE_FLAGS) -I../../../deps/cpp-statsd-client/include $(MODSNAP_CXX_FLAGS)
7+
$(CXX) -o $@ -c $< $(MODULE_FLAGS) -I../../../deps/cpp-statsd-client/include $(MODSNAP_CXX_FLAGS) -g
88

99
modstatsd.so: $(OBJECT_FILES)
1010
$(CXX) -shared $(OBJECT_FILES) -o modstatsd.so

src/object.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ robj *createObject(int type, void *ptr) {
4646
char *oB = (char*)zcalloc(sizeof(robj)+mvccExtraBytes, MALLOC_SHARED);
4747
robj *o = reinterpret_cast<robj*>(oB + mvccExtraBytes);
4848

49+
new (o) redisObject;
4950
o->type = type;
5051
o->encoding = OBJ_ENCODING_RAW;
5152
o->m_ptr = ptr;
@@ -418,6 +419,7 @@ void decrRefCount(robj_roptr o) {
418419
case OBJ_NESTEDHASH: freeNestedHashObject(o); break;
419420
default: serverPanic("Unknown object type"); break;
420421
}
422+
o->~redisObject();
421423
if (g_pserver->fActiveReplica) {
422424
zfree(reinterpret_cast<redisObjectExtended*>(o.unsafe_robjcast())-1);
423425
} else {

src/replication.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,8 @@ int bg_unlink(const char *filename) {
188188
/* ---------------------------------- MASTER -------------------------------- */
189189

190190
bool createDiskBacklog() {
191+
if (g_pserver->repl_backlog_disk != nullptr)
192+
return true; // already exists
191193
// Lets create some disk backed pages and add them here
192194
std::string path = "./repl-backlog-temp" + std::to_string(gettid());
193195
#if (defined __APPLE__ || defined __FreeBSD__)

src/server.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -966,6 +966,7 @@ struct redisObjectExtended {
966966

967967
typedef struct redisObject {
968968
friend redisObject *createEmbeddedStringObject(const char *ptr, size_t len);
969+
friend redisObject *createObject(int type, void *ptr);
969970
protected:
970971
redisObject() {}
971972

0 commit comments

Comments
 (0)