[CDRIVER-214] Fixed memory leak in mongo_replica_set_client Created: 13/May/13  Updated: 09/Aug/13  Resolved: 09/Aug/13

Status: Closed
Project: C Driver
Component/s: None
Affects Version/s: 0.7.1
Fix Version/s: 0.8.1

Type: Bug Priority: Minor - P4
Reporter: Daniel Brahneborg Assignee: Gary Murakami
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

mongo_replica_set_client() allocates memory for conn->primary, but if mongo_replica_set_init() has been called, that latter memory is lost. The patch adds a call to bson_free() before the new memory is allocated.

diff --git a/src/mongo.c b/src/mongo.c
index c8df093..904b1d9 100644
— a/src/mongo.c
+++ b/src/mongo.c
@@ -660,6 +660,7 @@ MONGO_EXPORT int mongo_replica_set_client( mongo *conn ) {

/* Primary found, so return. */
else if( conn->replica_set->primary_connected ) {
+ bson_free( conn->primary );
conn->primary = bson_malloc( sizeof( mongo_host_port ) );
strncpy( conn->primary->host, node->host, strlen( node->host ) + 1 );
conn->primary->port = node->port;



 Comments   
Comment by auto [ 09/Aug/13 ]

Author:

{u'username': u'gjmurakami-10gen', u'name': u'Gary J. Murakami', u'email': u'gary.murakami@10gen.com'}

Message: CDRIVER-214 Fixed memory leak in mongo_replica_set_client
Branch: master
https://github.com/mongodb/mongo-c-driver/commit/7795e65cd05762c121213e850144242c7a6de499

Generated at Wed Feb 07 21:08:47 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.