Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memory leak in command_simple #70

Open
kamulos opened this issue May 31, 2021 · 1 comment
Open

Memory leak in command_simple #70

kamulos opened this issue May 31, 2021 · 1 comment

Comments

@kamulos
Copy link

kamulos commented May 31, 2021

This is really strange

Reproduction

use bson::doc;
use mongo_driver::client::{ClientPool, Uri};

fn main() {
    let mongo_uri = Uri::new("mongodb://127.0.0.1:27017").unwrap();
    let pool = ClientPool::new(mongo_uri, None);
    let ping = doc! {"ping": 1};
    pool.pop()
        .get_database("admin")
        .command_simple(ping, None)
        .unwrap();
}

Run it with:

RUSTFLAGS="$RUSTFLAGS -Zsanitizer=address" cargo +nightly run --target=x86_64-unknown-linux-gnu

Possible reason

In database::command_simple(), when the bson_t is created the flags are set to 1, but after the bindings::mongoc_database_command_simple() the flags are set to 2. This means BSON_FLAG_STATIC which leads to skipping the free() in bson_destroy().

Not sure how this works internally, but this is my best guess...

@kamulos
Copy link
Author

kamulos commented Jun 25, 2021

I also forwarded this issue to the libmongoc issue tracker: https://jira.mongodb.org/browse/CDRIVER-4039

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

No branches or pull requests

1 participant