Skip to content

Commit ece5db1

Browse files
committed
CCBC-1674: Do not use non-owning spans to release memory with NETBUF_LIBC_PROXY
Fix use-after-free for build with NETBUF_LIBC_PROXY when snappy compression is enabled. This is special build when caching allocator is replaced with just libc malloc. It is used only during development and testing, and never enabled in production. Change-Id: If26d33c41819a475e99b40f9e6dddc3c15186170 Reviewed-on: https://review.couchbase.org/c/libcouchbase/+/232551 Reviewed-by: Michael Reiche <michael.reiche@couchbase.com> Tested-by: Build Bot <build@couchbase.com>
1 parent 8b51919 commit ece5db1

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

src/netbuf/netbuf.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -682,7 +682,9 @@ void netbuf_end_flush2(nb_MGR *mgr, unsigned int nflushed, nb_getsize_fn callbac
682682
void netbuf_mblock_release(nb_MGR *mgr, nb_SPAN *span)
683683
{
684684
#ifdef NETBUF_LIBC_PROXY
685-
free(span->parent);
685+
if (span->offset == 0) {
686+
free(span->parent);
687+
}
686688
(void)mgr;
687689
#else
688690
mblock_release_data(&mgr->datapool, span->parent, span->size, span->offset);

0 commit comments

Comments
 (0)