Skip to content

Conversation

kevinAlbs
Copy link
Collaborator

@kevinAlbs kevinAlbs commented Oct 2, 2025

Summary

Change mongoc_write_command_t::cmd_opts from bson_t to bson_t*.

Tested with this patch: https://spruce.mongodb.com/version/68dd762c5eafa20007be24b2

Background & Motivation

Intended to fix behavior when mongoc_write_command_t is copied into a mongoc_array_t. See comment in CDRIVER-6112 for a more detailed description. This PR proposes a simple fix: change bson_t to bson_t * to simplify ownership transfer.

Other instances of _mongoc_array_init were checked. No others appear to use an array of a type embedding bson_t. A comment is added to warn against storing bson_t in mongoc_array_t.

The memcpy does not correctly transfer ownership of the `bson_t` struct.
Instead: heap allocate the `bson_t` struct.
@kevinAlbs kevinAlbs marked this pull request as ready for review October 2, 2025 14:43
@kevinAlbs kevinAlbs requested a review from a team as a code owner October 2, 2025 14:43
Copy link
Contributor

@vector-of-bool vector-of-bool left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@kevinAlbs kevinAlbs merged commit ac38749 into mongodb:master Oct 3, 2025
44 of 46 checks passed
kevinAlbs added a commit to kevinAlbs/mongo-c-driver that referenced this pull request Oct 3, 2025
…odb#2132)

* add regression test
* do not memcpy `bson_t` struct in array
  * `memcpy` does not correctly transfer ownership of `bson_t`. Instead: heap allocate `bson_t`.
* warn against using `bson_t` in `mongoc_array_t`
kevinAlbs added a commit to kevinAlbs/mongo-c-driver that referenced this pull request Oct 3, 2025
…odb#2132)

* add regression test
* do not memcpy `bson_t` struct in array
  * `memcpy` does not correctly transfer ownership of `bson_t`. Instead: heap allocate `bson_t`.
* warn against using `bson_t` in `mongoc_array_t`
kevinAlbs added a commit that referenced this pull request Oct 6, 2025
… (#2137)

* add regression test
* do not memcpy `bson_t` struct in array
  * `memcpy` does not correctly transfer ownership of `bson_t`. Instead: heap allocate `bson_t`.
* warn against using `bson_t` in `mongoc_array_t`
kevinAlbs added a commit that referenced this pull request Oct 6, 2025
… (#2136)

* add regression test
* do not memcpy `bson_t` struct in array
  * `memcpy` does not correctly transfer ownership of `bson_t`. Instead: heap allocate `bson_t`.
* warn against using `bson_t` in `mongoc_array_t`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants