Use zfree_with_size for client buffer (#1376)

Replace occurrences of 'zfree' with 'zfree_with_size' to improve
performance.
'zfree_with_size' function avoids calling 'zmalloc_size' to retrieve
buffer size and
uses previuos calculation of size for calling 'zfree_with_size'. This
results in faster
memory deallocation and reduces overhead.

Signed-off-by: stav bentov <stavbt@amazon.com>
Co-authored-by: stav bentov <stavbt@amazon.com>
This commit is contained in:
Stav Ben-Tov 2024-12-01 13:24:18 +02:00 committed by GitHub
parent 4695d118dd
commit c8ceb2ee25
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 3 additions and 2 deletions

View File

@ -1760,7 +1760,7 @@ void freeClient(client *c) {
/* Free data structures. */
listRelease(c->reply);
c->reply = NULL;
zfree(c->buf);
zfree_with_size(c->buf, c->buf_usable_size);
c->buf = NULL;
freeReplicaReferencedReplBuffer(c);
freeClientArgv(c);

View File

@ -889,9 +889,10 @@ int clientsCronResizeOutputBuffer(client *c, mstime_t now_ms) {
if (new_buffer_size) {
oldbuf = c->buf;
size_t oldbuf_size = c->buf_usable_size;
c->buf = zmalloc_usable(new_buffer_size, &c->buf_usable_size);
memcpy(c->buf, oldbuf, c->bufpos);
zfree(oldbuf);
zfree_with_size(oldbuf, oldbuf_size);
}
return 0;
}