Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Free argv strings explicitly from Dram #201

Open
wants to merge 1 commit into
base: 6.0-memkind_alloc_by_size
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion src/object.c
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,11 @@ void freeStringObject(robj *o) {
sdsfree(o->ptr);
}
}
void freeStringObjectDram(robj *o) {
if (o->encoding == OBJ_ENCODING_RAW) {
sdsfreeDram(o->ptr);
}
}

void freeListObject(robj *o) {
if (o->encoding == OBJ_ENCODING_QUICKLIST) {
Expand Down Expand Up @@ -356,7 +361,15 @@ void incrRefCount(robj *o) {
static void _decrRefCount(robj *o, int on_dram) {
if (o->refcount == 1) {
switch(o->type) {
case OBJ_STRING: freeStringObject(o); break;
case OBJ_STRING:
if (on_dram == OBJ_MEMORY_GENERAL) {
freeStringObject(o);
}
else {
freeStringObjectDram(o);
}
break;

case OBJ_LIST: freeListObject(o); break;
case OBJ_SET: freeSetObject(o); break;
case OBJ_ZSET: freeZsetObject(o); break;
Expand Down
6 changes: 6 additions & 0 deletions src/sds.c
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,12 @@ void sdsfree(sds s) {
s_free((char*)s-sdsHdrSize(s[-1]));
}

/* Free an sds string. No operation is performed if 's' is NULL. */
void sdsfreeDram(sds s) {
if (s == NULL) return;
s_freeDram((char*)s-sdsHdrSize(s[-1]));
}

/* Set the sds string length to the length as obtained with strlen(), so
* considering as content only up to the first null term character.
*
Expand Down
1 change: 1 addition & 0 deletions src/sds.h
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ sds sdsempty(void);
sds sdsdramempty(void);
sds sdsdup(const sds s);
void sdsfree(sds s);
void sdsfreeDram(sds s);
sds sdsgrowzero(sds s, size_t len);
sds sdscatlen(sds s, const void *t, size_t len);
sds sdscat(sds s, const char *t);
Expand Down
1 change: 1 addition & 0 deletions src/sdsalloc.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
#define s_malloc zmalloc
#define s_realloc zrealloc
#define s_free zfree
#define s_freeDram zfree_dram
#define s_dram_malloc zmalloc_dram

#endif
1 change: 1 addition & 0 deletions src/server.h
Original file line number Diff line number Diff line change
Expand Up @@ -1724,6 +1724,7 @@ void incrRefCount(robj *o);
robj *makeObjectShared(robj *o);
robj *resetRefCount(robj *obj);
void freeStringObject(robj *o);
void freeStringObjectDram(robj *o);
void freeListObject(robj *o);
void freeSetObject(robj *o);
void freeZsetObject(robj *o);
Expand Down