-
Type: Bug
-
Resolution: Done
-
Priority: Minor - P4
-
Affects Version/s: 0.7.1
-
Component/s: None
-
None
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;