Fix bad memory accounting for sds when no malloc_size available (#694)

Issue Introduced  by #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 <ranshid@amazon.com>
This commit is contained in:
ranshid 2024-06-25 18:18:07 +03:00 committed by GitHub
parent 4d3d6c06a1
commit 3df9d42794
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 2 additions and 1 deletions

View File

@ -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;
}

View File

@ -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