Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
Signed-off-by: Madelyn Olson <madelyneolson@gmail.com>
  • Loading branch information
madolson authored Nov 22, 2024
1 parent ea9d4c7 commit 0ed8c4b
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/defrag.c
Original file line number Diff line number Diff line change
Expand Up @@ -238,14 +238,14 @@ static sds activeDefragSds(sds sdsptr) {
* caller's responsibility. This is necessary for string objects with multiple references. In this
* case the caller can fix the references before freeing the original object.
*/
static robj *activeDefragStringObWithoutFree(robj *ob) {
static robj *activeDefragStringObWithoutFree(robj *ob, size_t *allocation_size) {
if (ob->type == OBJ_STRING && ob->encoding == OBJ_ENCODING_RAW) {
// Try to defrag the linked sds, regardless of if robj will be moved
sds newsds = activeDefragSds((sds)ob->ptr);
if (newsds) ob->ptr = newsds;
}

robj *new_robj = activeDefragAllocWithoutFree(ob, NULL);
robj *new_robj = activeDefragAllocWithoutFree(ob, allocation_size);

if (new_robj && ob->type == OBJ_STRING && ob->encoding == OBJ_ENCODING_EMBSTR) {
// If the robj is moved, correct the internal pointer
Expand Down Expand Up @@ -858,7 +858,8 @@ static void defragPubsubScanCallback(void *privdata, const dictEntry *de) {

/* Try to defrag the channel name. */
serverAssert(channel->refcount == (int)dictSize(clients) + 1);
newchannel = activeDefragStringObWithoutFree(channel);
size_t size;
newchannel = activeDefragStringObWithoutFree(channel, &size);
if (newchannel) {
kvstoreDictSetKey(pubsub_channels, ctx->kvstate.slot, (dictEntry *)de, newchannel);

Expand All @@ -876,7 +877,7 @@ static void defragPubsubScanCallback(void *privdata, const dictEntry *de) {
}
dictReleaseIterator(di);
// Now that we're done correcting the references, we can safely free the old channel robj
zfree_no_tcache(channel);
allocatorDefragFree(channel, size);
}

/* Try to defrag the dictionary of clients that is stored as the value part. */
Expand Down

0 comments on commit 0ed8c4b

Please sign in to comment.