Memory leak when rewriting packet to set collection id

Description

In mixed-version cluster, with 7.2 and 6.6 nodes, it is possible when libcouchbase will decide to rewrite packet to insert ID of the default collection:
https://github.com/couchbase/libcouchbase/blob/684931e59cd87e0c6292e8142c2b18897be5b10c/src/mc/mcreq.c#L291

This side effect should be accounted for every time check_collection_id() is invoked, so that the caller will always update local pointers to the packet, and do not try to preserve pointer to the old packet.

The issue is in
https://github.com/couchbase/libcouchbase/blob/684931e59cd87e0c6292e8142c2b18897be5b10c/src/mc/mcreq.c#L334C6-L340

void mcreq_enqueue_packet(mc_PIPELINE *pipeline, mc_PACKET *packet) { nb_SPAN *vspan = &packet->u_value.single; sllist_append(&pipeline->requests, &packet->slnode); packet = check_collection_id(pipeline, packet); netbuf_enqueue_span(&pipeline->nbmgr, &packet->kh_span, packet);

Which preserves old pointer in "pipeline->requests" list, leaving that piece of memory leaking and accumulating over run time. The fix moves the check to the top of the function.

Environment

None

Gerrit Reviews

None

Release Notes Description

None

Activity

Show:

CB robot February 25, 2025 at 2:06 AM

Build couchbase-columnar-1.2.0-1009 contains libcouchbase commit 9a7498b with commit message:
CCBC-1630: check collection id before storing packet to pipeline

CB robot February 25, 2025 at 1:33 AM

Build couchbase-columnar-1.2.0-1009 contains libcouchbase commit 9a7498b with commit message:
CCBC-1630: check collection id before storing packet to pipeline

CB robot February 24, 2025 at 10:00 PM

Build couchbase-columnar-1.2.0-1009 contains libcouchbase commit 9a7498b with commit message:
CCBC-1630: check collection id before storing packet to pipeline

CB robot December 12, 2024 at 5:56 PM

Build couchbase-columnar-1.1.0-1155 contains libcouchbase commit 9a7498b with commit message:
CCBC-1630: check collection id before storing packet to pipeline

CB robot November 25, 2024 at 6:38 AM

Build couchbase-server-7.6.5-5537 contains libcouchbase commit 9a7498b with commit message:
https://couchbasecloud.atlassian.net/browse/CCBC-1630#icft=CCBC-1630: check collection id before storing packet to pipeline

Fixed
Pinned fields
Click on the next to a field label to start pinning.

Details

Assignee

Fix versions

Sprint

Story Points

Reporter

Priority

Instabug

Open Instabug

PagerDuty

Sentry

Zendesk Support

Created February 16, 2024 at 1:01 AM
Updated February 25, 2025 at 2:06 AM
Resolved February 16, 2024 at 3:02 AM
Instabug