From: Andrey Kuznetsov Date: Thu, 19 Jun 2014 13:56:01 +0000 (+0400) Subject: [RGW, memory leaks] Memory leak in RGW initialization (Inserting new connection into... X-Git-Tag: v0.84~167^2~2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=8706b74e0368916c2fbbbbed55d1dbaa10e7ff2b;p=ceph.git [RGW, memory leaks] Memory leak in RGW initialization (Inserting new connection into connections map w/o check) has been fixed. 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 --- diff --git a/src/rgw/rgw_rados.cc b/src/rgw/rgw_rados.cc index bef9718c1236a..897922f314890 100644 --- a/src/rgw/rgw_rados.cc +++ b/src/rgw/rgw_rados.cc @@ -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 ®ion_conn_map, RGWRegion ®ion, RGWRESTConn *new_connection) +{ + // Delete if connection is already exists + map::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)); } }