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

Fixed memory leak in mongo_replica_set_client

    XMLWordPrintableJSON

Details

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Minor - P4 Minor - P4
    • 0.8.1
    • 0.7.1
    • None
    • None

    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;

      Attachments

        Activity

          People

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

            Dates

              Created:
              Updated:
              Resolved: