From 6c2bb66f15d7ab8ab079effc66e0705c2513b1fd Mon Sep 17 00:00:00 2001 From: Mark Reynolds Date: Mar 29 2019 13:18:44 +0000 Subject: Ticket 50308 - Fix memory leaks for repeat binds and replication Description: Fixed two memory leaks: - If a worker thread had multiple binds the "bind dn" thread data was leaked. - Memory leak when processing changes in the changelog https://pagure.io/389-ds-base/issue/50308 Reviewed by: firstyear(Thanks!) --- diff --git a/ldap/servers/plugins/replication/cl5_clcache.c b/ldap/servers/plugins/replication/cl5_clcache.c index a8477a8..6c18829 100644 --- a/ldap/servers/plugins/replication/cl5_clcache.c +++ b/ldap/servers/plugins/replication/cl5_clcache.c @@ -589,6 +589,7 @@ clcache_refresh_local_maxcsn(const ruv_enum_data *rid_data, void *data) /* this is the first time we have a local change for the RID * we need to check what the consumer knows about it. */ + csn_free(&buf->buf_cscbs[i]->consumer_maxcsn); ruv_get_largest_csn_for_replica( buf->buf_consumer_ruv, buf->buf_cscbs[i]->rid, @@ -832,6 +833,7 @@ clcache_skip_change(CLC_Buffer *buf) /* Send CSNs that are covered by the local RUV snapshot */ if (csn_compare(buf->buf_current_csn, cscb->local_maxcsn) <= 0) { skip = 0; + csn_free(&cscb->consumer_maxcsn); csn_dup_or_init_by_csn(&cscb->consumer_maxcsn, buf->buf_current_csn); break; } @@ -842,11 +844,12 @@ clcache_skip_change(CLC_Buffer *buf) * are not sure if current_csn is the neighbor. */ if (csn_time_difference(buf->buf_current_csn, cscb->local_maxcsn) == 0 && - (csn_get_seqnum(buf->buf_current_csn) == - csn_get_seqnum(cscb->local_maxcsn) + 1)) { + (csn_get_seqnum(buf->buf_current_csn) == csn_get_seqnum(cscb->local_maxcsn) + 1)) + { csn_init_by_csn(cscb->local_maxcsn, buf->buf_current_csn); if (cscb->consumer_maxcsn) { - csn_init_by_csn(cscb->consumer_maxcsn, buf->buf_current_csn); + csn_free(&cscb->consumer_maxcsn); + csn_dup_or_init_by_csn(cscb->consumer_maxcsn, buf->buf_current_csn); } skip = 0; break; diff --git a/ldap/servers/slapd/thread_data.c b/ldap/servers/slapd/thread_data.c index 7babe36..fb9951d 100644 --- a/ldap/servers/slapd/thread_data.c +++ b/ldap/servers/slapd/thread_data.c @@ -98,6 +98,8 @@ slapi_td_get_plugin_locked() int32_t slapi_td_set_dn(char *value) { + char *dn = pthread_getspecific(td_requestor_dn); + slapi_ch_free_string(&dn); if (pthread_setspecific(td_requestor_dn, value) != 0) { return PR_FAILURE; }