Fixes for various memory leaks found during testing.
>From 1d79c10d9d3351459fd52e84cb30e4b0e65a61b9 Mon Sep 17 00:00:00 2001 From: Rich Megginson <rmeggins@xxxxxxxxxx> Date: Thu, 4 Mar 2010 14:02:29 -0700 Subject: [PATCH] fix various memory leaks var/tmp/run_gssapi.vg.25032:Memory leak: 99 bytes duplicates: 5 > malloc() at vg_replace_malloc.c:207 > strdup() at /lib/libc-2.10.2.so > slapi_ch_strdup() at ch_malloc.c:277 > ids_sasl_check_bind() at saslbind.c:924 > do_bind() at bind.c:382 > connection_threadmain() at connection.c:554 > --unknown-- at /lib/libnspr4.so > start_thread() at /lib/libpthread-2.10.2.so > clone() at /lib/libc-2.10.2.so The problem is that ids_sasl_check_bind can reset SLAPI_BIND_TARGET to a malloc'd value. The do_bind() code should check for this condition and free it. var/tmp/entryusn.vg.5997:Memory leak: 8 bytes duplicates: 8 > calloc() at vg_replace_malloc.c:397 > slapi_ch_calloc() at ch_malloc.c:243 > slapi_counter_new() at slapi_counter.c:95 > ldbm_usn_init() at ldbm_usn.c:86 > ldbm_back_start() at start.c:223 > plugin_call_func() at plugin.c:1417 > plugin_dependency_startall.clone.0() at plugin.c:1385 > main() at main.c:1138 The backend cleanup code should free be_usn_counter. var/tmp/ipv6.vg.15561:Memory leak: 13 bytes duplicates: 3 > malloc() at vg_replace_malloc.c:207 > strdup() at /lib/libc-2.10.2.so > slapi_ch_strdup() at ch_malloc.c:277 > config_get_listenhost() at libglobs.c:3674 > main() at main.c:874 var/tmp/ipv6.vg.15561:Memory leak: 13 bytes duplicates: 3 > malloc() at vg_replace_malloc.c:207 > strdup() at /lib/libc-2.10.2.so > slapi_ch_strdup() at ch_malloc.c:277 > config_get_securelistenhost() at libglobs.c:3686 > main() at main.c:881 config_get_listenhost() and config_get_securelistenhost() return malloc'd memory which must be freed. var/tmp/dna_scen1.vg.4901:Memory leak: 248 bytes duplicates: 1 > malloc() at vg_replace_malloc.c:207 > nslberi_malloc() at io.c:1677 > ber_flatten() at io.c:1604 > create_NSDS50ReplicationExtopPayload() at repl_extop.c:218 > NSDS50EndReplicationRequest_new() at repl_extop.c:265 > release_replica() at repl5_protocol_util.c:469 > repl5_inc_run() at repl5_inc_protocol.c:1187 > prot_thread_main() at repl5_protocol.c:341 > --unknown-- at /lib/libnspr4.so > start_thread() at /lib/libpthread-2.10.2.so > clone() at /lib/libc-2.10.2.so The payload was not being freed under all function exit conditions. So, just free it immediately after use. var/tmp/dnarun.vg.2491:Memory leak: 27 bytes duplicates: 0 > malloc() at vg_replace_malloc.c:207 > slapi_ch_malloc() at ch_malloc.c:155 > slapi_entry_attr_get_charptr() at entry.c:2432 > dna_parse_config_entry() at dna.c:816 > dna_pre_op() at dna.c:2587 > plugin_call_func() at plugin.c:1417 > plugin_call_plugins() at plugin.c:1379 > op_shared_add() at add.c:606 > do_add() at add.c:232 > connection_threadmain() at connection.c:564 > --unknown-- at /lib/libnspr4.so > start_thread() at /lib/libpthread-2.10.2.so > clone() at /lib/libc-2.10.2.so The value was not being freed under all conditions. ==9877== 1,890 (252 direct, 1,638 indirect) bytes in 3 blocks are definitely lost in loss record 1,628 of 1,725 ==9877== at 0x47E0E5C: calloc (vg_replace_malloc.c:397) ==9877== by 0x4819D89: slapi_ch_calloc (ch_malloc.c:243) ==9877== by 0x48284A6: slapi_entry_alloc (entry.c:1686) ==9877== by 0x4829BA5: str2entry_dupcheck (entry.c:631) ==9877== by 0x482BB5D: slapi_str2entry_ext (entry.c:1194) ==9877== by 0xB2A8E9D: import_producer (import-threads.c:541) ==9877== by 0x72E1990: (within /lib/libnspr4.so) ==9877== by 0x731E8F4: start_thread (in /lib/libpthread-2.10.2.so) ==9877== by 0x75B2FCD: clone (in /lib/libc-2.10.2.so) Make sure the entry or backentry are freed. --- ldap/servers/plugins/dna/dna.c | 2 ++ .../plugins/replication/repl5_protocol_util.c | 3 +-- ldap/servers/slapd/back-ldbm/import-threads.c | 6 ++++++ ldap/servers/slapd/backend.c | 1 + ldap/servers/slapd/bind.c | 6 ++++++ ldap/servers/slapd/main.c | 11 +++++++++-- 6 files changed, 25 insertions(+), 4 deletions(-) diff --git a/ldap/servers/plugins/dna/dna.c b/ldap/servers/plugins/dna/dna.c index 011821b..c82bf6b 100644 --- a/ldap/servers/plugins/dna/dna.c +++ b/ldap/servers/plugins/dna/dna.c @@ -833,6 +833,7 @@ dna_parse_config_entry(Slapi_Entry * e, int apply) "dna_parse_config_entry: Unable to locate " "shared configuration entry (%s)\n", value); ret = DNA_FAILURE; + slapi_ch_free_string(&value); goto bail; } else { slapi_entry_free(shared_e); @@ -845,6 +846,7 @@ dna_parse_config_entry(Slapi_Entry * e, int apply) * multi-part RDN for the shared config entry. */ entry->shared_cfg_dn = slapi_ch_smprintf("%s=%s+%s=%s,%s", DNA_HOSTNAME, hostname, DNA_PORTNUM, portnum, value); + slapi_ch_free_string(&value); slapi_dn_normalize(entry->shared_cfg_dn); slapi_log_error(SLAPI_LOG_CONFIG, DNA_PLUGIN_SUBSYSTEM, diff --git a/ldap/servers/plugins/replication/repl5_protocol_util.c b/ldap/servers/plugins/replication/repl5_protocol_util.c index f1b7036..3fbc978 100644 --- a/ldap/servers/plugins/replication/repl5_protocol_util.c +++ b/ldap/servers/plugins/replication/repl5_protocol_util.c @@ -470,6 +470,7 @@ release_replica(Private_Repl_Protocol *prp) slapi_sdn_free(&replarea_sdn); rc = conn_send_extended_operation(prp->conn, REPL_END_NSDS50_REPLICATION_REQUEST_OID, payload, NULL /* update control */, &sent_message_id /* Message ID */); + ber_bvfree(payload); /* done with this - free it now */ if (0 != rc) { int operation, error; @@ -538,8 +539,6 @@ release_replica(Private_Repl_Protocol *prp) ber_bvecfree(ruv_bervals); /* XXXggood free ruv_bervals if we got them for some reason */ } - if (NULL != payload) - ber_bvfree(payload); if (NULL != retoid) ldap_memfree(retoid); if (NULL != retdata) diff --git a/ldap/servers/slapd/back-ldbm/import-threads.c b/ldap/servers/slapd/back-ldbm/import-threads.c index efcea3e..892fd8e 100644 --- a/ldap/servers/slapd/back-ldbm/import-threads.c +++ b/ldap/servers/slapd/back-ldbm/import-threads.c @@ -559,6 +559,10 @@ import_producer(void *param) if (! import_entry_belongs_here(e, inst->inst_be)) { /* silently skip */ + if (e) { + slapi_entry_free(e); + } + continue; } @@ -661,6 +665,7 @@ import_producer(void *param) } if (job->flags & FLAG_ABORT) { + backentry_free(&ep); goto error; } @@ -689,6 +694,7 @@ import_producer(void *param) DS_Sleep(sleeptime); } if (job->flags & FLAG_ABORT){ + backentry_free(&ep); goto error; } info->state = RUNNING; diff --git a/ldap/servers/slapd/backend.c b/ldap/servers/slapd/backend.c index f57bc23..4b2d928 100644 --- a/ldap/servers/slapd/backend.c +++ b/ldap/servers/slapd/backend.c @@ -115,6 +115,7 @@ be_done(Slapi_Backend *be) slapi_ch_free((void **)&be->be_backendconfig); /* JCM char **be_include; ??? */ slapi_ch_free((void **)&be->be_name); + slapi_counter_destroy(&be->be_usn_counter); PR_DestroyLock(be->be_state_lock); if (be->be_lock != NULL) { diff --git a/ldap/servers/slapd/bind.c b/ldap/servers/slapd/bind.c index 8c5bc6b..3458ff6 100644 --- a/ldap/servers/slapd/bind.c +++ b/ldap/servers/slapd/bind.c @@ -135,6 +135,7 @@ do_bind( Slapi_PBlock *pb ) Slapi_Entry *bind_target_entry = NULL; int auto_bind = 0; int minssf = 0; + char *test_bind_dn = NULL; LDAPDebug( LDAP_DEBUG_TRACE, "do_bind\n", 0, 0, 0 ); @@ -745,6 +746,11 @@ do_bind( Slapi_PBlock *pb ) free_and_return:; if (be) slapi_be_Unlock(be); + slapi_pblock_get(pb, SLAPI_BIND_TARGET, &test_bind_dn); + if (test_bind_dn != slapi_sdn_get_ndn(&sdn)) { + /* set in sasl bind or some other bind plugin */ + slapi_ch_free_string(&test_bind_dn); + } slapi_sdn_done(&sdn); slapi_ch_free_string( &saslmech ); slapi_ch_free( (void **)&cred.bv_val ); diff --git a/ldap/servers/slapd/main.c b/ldap/servers/slapd/main.c index 375fc4a..5023dcd 100644 --- a/ldap/servers/slapd/main.c +++ b/ldap/servers/slapd/main.c @@ -870,19 +870,26 @@ main( int argc, char **argv) if ((slapd_exemode == SLAPD_EXEMODE_SLAPD) || (slapd_exemode == SLAPD_EXEMODE_REFERRAL)) { + char *listenhost = config_get_listenhost(); + char *securelistenhost = config_get_securelistenhost(); ports_info.n_port = (unsigned short)n_port; - if ( slapd_listenhost2addr( config_get_listenhost(), + if ( slapd_listenhost2addr( listenhost, &ports_info.n_listenaddr ) != 0 || ports_info.n_listenaddr == NULL ) { + slapi_ch_free_string(&listenhost); + slapi_ch_free_string(&securelistenhost); return(1); } + slapi_ch_free_string(&listenhost); ports_info.s_port = (unsigned short)s_port; - if ( slapd_listenhost2addr( config_get_securelistenhost(), + if ( slapd_listenhost2addr( securelistenhost, &ports_info.s_listenaddr ) != 0 || ports_info.s_listenaddr == NULL ) { + slapi_ch_free_string(&securelistenhost); return(1); } + slapi_ch_free_string(&securelistenhost); #if defined(ENABLE_LDAPI) if( config_get_ldapi_switch() && -- 1.5.5.6
-- 389-devel mailing list 389-devel@xxxxxxxxxxxxxxxxxxxxxxx https://admin.fedoraproject.org/mailman/listinfo/389-devel