<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Wed Feb 07 21:09:31 UTC 2024

It is possible to restrict the fields that are returned in this document by specifying the 'field' parameter in your request.
For example, to request only the issue key and summary append 'field=key&field=summary' to the URL of your request.
-->
<rss version="0.92" >
<channel>
    <title>MongoDB Jira</title>
    <link>https://jira.mongodb.org</link>
    <description>This file is an XML representation of an issue</description>
    <language>en-us</language>    <build-info>
        <version>9.7.1</version>
        <build-number>970001</build-number>
        <build-date>13-04-2023</build-date>
    </build-info>


<item>
            <title>[CDRIVER-446] Memory leak in mongoc_client_command_simple()</title>
                <link>https://jira.mongodb.org/browse/CDRIVER-446</link>
                <project id="10030" key="CDRIVER">C Driver</project>
                    <description>&lt;p&gt;when I call mongoc_database_get_collection_info() a new bson is created:&lt;br/&gt;
&lt;a href=&quot;https://github.com/mongodb/mongo-c-driver/blob/048c851919dc32c98b5f8a9a0270e69af9385db3/src/mongoc/mongoc-database.c#L741&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/mongodb/mongo-c-driver/blob/048c851919dc32c98b5f8a9a0270e69af9385db3/src/mongoc/mongoc-database.c#L741&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;the bson correct. But, this bson is sent to mongoc_database_command_simple() and then to mongoc_client_command_simple()&lt;/p&gt;

&lt;p&gt;The issue is this bson is sent to bson_init() :&lt;br/&gt;
&lt;a href=&quot;https://github.com/mongodb/mongo-c-driver/blob/048c851919dc32c98b5f8a9a0270e69af9385db3/src/mongoc/mongoc-client.c#L1247&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/mongodb/mongo-c-driver/blob/048c851919dc32c98b5f8a9a0270e69af9385db3/src/mongoc/mongoc-client.c#L1247&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;so the flags of this bson changes from BSON_FLAG_INLINE to BSON_FLAG_INLINE | BSON_FLAG_STATIC&lt;/p&gt;

&lt;p&gt;So later when bson_destroy() is called, the buffer is not freed()&lt;/p&gt;

&lt;p&gt;I think bson_reinit() should be called instead. But I&apos;m not sure. I&apos;m not even sure if we need to call something on this bson.&lt;/p&gt;
</description>
                <environment></environment>
        <key id="164397">CDRIVER-446</key>
            <summary>Memory leak in mongoc_client_command_simple()</summary>
                <type id="1" iconUrl="https://jira.mongodb.org/secure/viewavatar?size=xsmall&amp;avatarId=14703&amp;avatarType=issuetype">Bug</type>
                                            <priority id="3" iconUrl="https://jira.mongodb.org/images/icons/priorities/major.svg">Major - P3</priority>
                        <status id="6" iconUrl="https://jira.mongodb.org/images/icons/statuses/closed.png" description="The issue is considered finished, the resolution is correct. Issues which are closed can be reopened.">Closed</status>
                    <statusCategory id="3" key="done" colorName="success"/>
                                    <resolution id="9">Done</resolution>
                                        <assignee username="mira.carey@mongodb.com">Mira Carey</assignee>
                                    <reporter username="jeromelebel">Jerome Lebel</reporter>
                        <labels>
                    </labels>
                <created>Sun, 19 Oct 2014 22:23:33 +0000</created>
                <updated>Wed, 19 Oct 2016 14:15:02 +0000</updated>
                            <resolved>Wed, 5 Nov 2014 18:20:55 +0000</resolved>
                                    <version> 1.0.2 </version>
                                    <fixVersion>1.1.0</fixVersion>
                                                        <votes>0</votes>
                                    <watches>2</watches>
                                                                                                                <comments>
                            <comment id="758278" author="jeromelebel" created="Thu, 6 Nov 2014 21:54:15 +0000"  >&lt;p&gt;My idea was to say all bson from reply as to be initialized. That we can either do:&lt;br/&gt;
bson command_reply = BSON_INITIALIZER;&lt;br/&gt;
mongoc_database_command_simple(database, &amp;amp;cmd, read_prefs, &amp;amp;command_reply, error);&lt;/p&gt;

&lt;p&gt;bson *command_reply = bson_new();&lt;br/&gt;
mongoc_database_command_simple(database, &amp;amp;cmd, read_prefs, &amp;amp;command_reply, error);&lt;/p&gt;

&lt;p&gt;for me this should not be allowed:&lt;br/&gt;
bson command_reply;&lt;/p&gt;

&lt;p&gt;only this should exist:&lt;br/&gt;
bson command_reply = BSON_INITIALIZER;&lt;/p&gt;

&lt;p&gt;But well that&apos;s my personal opinion, and as long as I don&apos;t have memory leaks, I&apos;m happy.&lt;/p&gt;


&lt;p&gt;Thanks!&lt;/p&gt;</comment>
                            <comment id="758267" author="jeromelebel" created="Thu, 6 Nov 2014 21:47:17 +0000"  >&lt;p&gt;Sorry, I made a mistake between branches. I tested a branch that doesn&apos;t have your fix yet. I tried the master, I don&apos;t see the leak anymore!&lt;/p&gt;

&lt;p&gt;Thanks.&lt;/p&gt;</comment>
                            <comment id="757809" author="jason.carey" created="Thu, 6 Nov 2014 16:04:48 +0000"  >&lt;p&gt;I&apos;m not sure where you&apos;re seeing that leak.  I&apos;ve been making sure to run the test suite through valgrind and confirmed the leak you were seeing, fixed it, and then observed that valgrind no longer reported the leak.  If there&apos;s a use case I&apos;ve missed I&apos;d be happy to add it to the test suite and reopen this.&lt;/p&gt;

&lt;p&gt;I&apos;m sorry if you&apos;re not thrilled with the way I fixed this, but I had a couple of constraints I tried to work within:&lt;/p&gt;
&lt;ul&gt;
	&lt;li&gt;mongoc_client_command_simple() expects an uninitialized stack allocated reply.  That&apos;s not as specific as it should have been, and probably justifies some more explicit documentation, but that&apos;s the contract at this point.  I don&apos;t really want to break users who have figured that out.&lt;/li&gt;
	&lt;li&gt;There&apos;s no way to identify an uninitialized stack allocation.  We don&apos;t demand that users zero bson_t&apos;s before passing them through libmongoc api, or that they use the static initializer, so we can&apos;t rely on any kind of bit pattern to identify bson_t&apos;s with an existing heap allocation.&lt;/li&gt;
	&lt;li&gt;I can work around that by providing a stack allocation and then copying it into a heap allocated reply and passing that back.   Which is the fix here.  It&apos;s not ideal, but it works around an otherwise unavoidable memory leak in mongoc_database_get_collection_info()&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;I apologize if I&apos;m missing something obvious, but I don&apos;t see how database_get_collection_info leaks at this point in master&lt;/p&gt;</comment>
                            <comment id="757289" author="jeromelebel" created="Wed, 5 Nov 2014 22:39:42 +0000"  >&lt;p&gt;There is still a memory leak in mongoc_client_command_simple() when using mongoc_database_get_collection_info()&lt;/p&gt;</comment>
                            <comment id="756172" author="jeromelebel" created="Tue, 4 Nov 2014 22:36:40 +0000"  >&lt;p&gt;I don&apos;t really understand why it is fixed. bson_init() is still called, therefore the flags are still changed. Anyone who doesn&apos;t know this issue will create a memory leak.&lt;/p&gt;

&lt;p&gt;For me the consequences are fixed, but not the origin of this bug.&lt;/p&gt;</comment>
                            <comment id="756141" author="xgen-internal-githook" created="Tue, 4 Nov 2014 22:16:11 +0000"  >&lt;p&gt;Author:&lt;/p&gt;
{u&apos;username&apos;: u&apos;hanumantmk&apos;, u&apos;name&apos;: u&apos;Jason Carey (hanumantmk)&apos;, u&apos;email&apos;: u&apos;jcarey@argv.me&apos;}
&lt;p&gt;Message: &lt;a href=&quot;https://jira.mongodb.org/browse/CDRIVER-446&quot; title=&quot;Memory leak in mongoc_client_command_simple()&quot; class=&quot;issue-link&quot; data-issue-key=&quot;CDRIVER-446&quot;&gt;&lt;del&gt;CDRIVER-446&lt;/del&gt;&lt;/a&gt; Fix a leak in mongoc_client_command_simple()&lt;/p&gt;

&lt;p&gt;fix a leak in mongoc_client_command_simple().&lt;/p&gt;

&lt;p&gt;Fix some other random leaks while we&apos;re at it&lt;/p&gt;

&lt;p&gt;Closes #110&lt;br/&gt;
Branch: master&lt;br/&gt;
&lt;a href=&quot;https://github.com/mongodb/mongo-c-driver/commit/021a050ef5705515acb7e391b0bfe9950f17cee1&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/mongodb/mongo-c-driver/commit/021a050ef5705515acb7e391b0bfe9950f17cee1&lt;/a&gt;&lt;/p&gt;</comment>
                    </comments>
                    <attachments>
                    </attachments>
                <subtasks>
                    </subtasks>
                <customfields>
                                                                                                                                                                                                                                                                                                                                                                    <customfield id="customfield_15850" key="com.atlassian.jira.plugins.jira-development-integration-plugin:devsummary">
                        <customfieldname>Development</customfieldname>
                        <customfieldvalues>
                            
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            <customfield id="customfield_12550" key="com.pyxis.greenhopper.jira:gh-lexo-rank">
                        <customfieldname>Rank</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>2|hrf7vb:</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_10558" key="com.pyxis.greenhopper.jira:gh-global-rank">
                        <customfieldname>Rank (Obsolete)</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>1170</customfieldvalue>
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                    <customfield id="customfield_10557" key="com.pyxis.greenhopper.jira:gh-sprint">
                        <customfieldname>Sprint</customfieldname>
                        <customfieldvalues>
                                <customfieldvalue id="304">C Sprint 9</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            </customfields>
    </item>
</channel>
</rss>