Skip to content

Commit

Permalink
Fix bad memory accounting for sds when no malloc_size available (valk…
Browse files Browse the repository at this point in the history
…ey-io#694)

Issue Introduced  by valkey-io#453. 
When we check the SDS _TYPE_5 allocation size we mistakenly used
zmalloc_size which DOES take the PREFIX size into account when no
malloc_size support.
Later when we free we add the PREFIX_SIZE again which leads to negative
memory accounting on some tests.
Example test failure:
https://github.com/valkey-io/valkey/actions/runs/9654170962/job/26627901497

Signed-off-by: ranshid <[email protected]>
  • Loading branch information
ranshid authored Jun 25, 2024
1 parent 4d3d6c0 commit 3df9d42
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/sds.c
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ size_t sdsAllocSize(sds s) {
char type = s[-1] & SDS_TYPE_MASK;
/* SDS_TYPE_5 header doesn't contain the size of the allocation */
if (type == SDS_TYPE_5) {
return s_malloc_size(sdsAllocPtr(s));
return s_malloc_usable_size(sdsAllocPtr(s));
} else {
return sdsHdrSize(type) + sdsalloc(s) + 1;
}
Expand Down
1 change: 1 addition & 0 deletions src/sdsalloc.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,6 @@
#define s_trymalloc_usable ztrymalloc_usable
#define s_tryrealloc_usable ztryrealloc_usable
#define s_malloc_size zmalloc_size
#define s_malloc_usable_size zmalloc_usable_size

#endif

0 comments on commit 3df9d42

Please sign in to comment.