]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
[RGW, memory leaks] Memory leak in RGW initialization (Inserting new connection into...
authorAndrey Kuznetsov <Andrey_Kuznetsov@epam.com>
Thu, 19 Jun 2014 13:56:01 +0000 (17:56 +0400)
committerferus.tigris@gmail.com <ferus.tigris@gmail.com>
Sun, 29 Jun 2014 18:26:16 +0000 (22:26 +0400)
Memory leaks detector report:

$ valgrind  --leak-check=full /usr/bin/radosgw -c /etc/ceph/ceph.conf -n
client.radosgw.gateway -f
...
=16986== 1,262 (48 direct, 1,214 indirect) bytes in 1 blocks are definitely lost in loss record 81
of 83
==16986==    at 0x4A075BC: operator new(unsigned long) (vg_replace_malloc.c:298)
==16986==    by 0x618F0D: RGWRados::init_complete() (in /usr/bin/radosgw)
==16986==    by 0x618FE6: RGWRados::initialize() (in /usr/bin/radosgw)
==16986==    by 0x63BB23: RGWRados::initialize(CephContext*, bool) (in /usr/bin/radosgw)
==16986==    by 0x634D20: RGWStoreManager::init_storage_provider(CephContext*, bool) (in
/usr/bin/radosgw)
==16986==    by 0x5B8970: RGWStoreManager::get_storage(CephContext*, bool) (in /usr/bin/radosgw)
==16986==    by 0x5B6D5D: main (in /usr/bin/radosgw)
...

Signed-off-by: Andrey Kuznetsov <Andrey_Kuznetsov@epam.com>
src/rgw/rgw_rados.cc

index bef9718c1236a335b19d9726934a877f78178ade..897922f3148909d87f99fef51580d520d24d81cf 100644 (file)
@@ -1392,6 +1392,24 @@ int RGWRados::init_rados()
   return ret;
 }
 
+/**
+ * Add new connection to connections map
+ * @param region_conn_map map which new connection will be added to 
+ * @param region region which new connection will connect to
+ * @param new_connection pointer to new connection instance
+ */
+static void add_new_connection_to_map(map<string, RGWRESTConn *> &region_conn_map, RGWRegion &region, RGWRESTConn *new_connection) 
+{
+  // Delete if connection is already exists
+  map<string, RGWRESTConn *>::iterator iterRegion = region_conn_map.find(region.name);
+  if (iterRegion != region_conn_map.end()) {
+    delete iterRegion->second;
+  }
+    
+  // Add new connection to connections map
+  region_conn_map[region.name] = new_connection;
+}
+
 /** 
  * Initialize the RADOS instance and prepare to do other ops
  * Returns 0 on success, -ERR# on failure.
@@ -1434,8 +1452,7 @@ int RGWRados::init_complete()
 
     for (iter = region_map.regions.begin(); iter != region_map.regions.end(); ++iter) {
       RGWRegion& region = iter->second;
-
-      region_conn_map[region.name] = new RGWRESTConn(cct, this, region.endpoints);
+      add_new_connection_to_map(region_conn_map, region, new RGWRESTConn(cct, this, region.endpoints));
     }
   }