Uploaded image for project: 'C Driver'
  1. C Driver
  2. CDRIVER-214

Fixed memory leak in mongo_replica_set_client

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Minor - P4 Minor - P4
    • 0.8.1
    • 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;

            Assignee:
            gjmurakami Gary Murakami
            Reporter:
            basic70 Daniel Brahneborg
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: