From 46fb7cee43a396ed9f58b2d6a7495c6dba4948c4 Mon Sep 17 00:00:00 2001 From: Simon Pichugin Date: Apr 15 2020 08:50:07 +0000 Subject: Issue 51016 - Fix memory leaks in changelog5_init and perfctrs_init Bug Description: Memory Leaks are detected by ASAN in changelog5_init and perfctrs_init functions. Fix Description: For perfctrs_init, free existing memory before initializing new memory which will be assigned to the existing stucts. For changelog5_init, run cl5Cleanup instead of cl5Close for BE preop. https://pagure.io/389-ds-base/issue/51016 Reviewed by: lkrispen (Thanks!) --- diff --git a/ldap/servers/plugins/replication/repl5_init.c b/ldap/servers/plugins/replication/repl5_init.c index 5badd7c..5a748e3 100644 --- a/ldap/servers/plugins/replication/repl5_init.c +++ b/ldap/servers/plugins/replication/repl5_init.c @@ -338,7 +338,7 @@ multimaster_bepreop_init(Slapi_PBlock *pb) if (slapi_pblock_set(pb, SLAPI_PLUGIN_VERSION, SLAPI_PLUGIN_VERSION_01) != 0 || slapi_pblock_set(pb, SLAPI_PLUGIN_DESCRIPTION, (void *)&multimasterbepreopdesc) != 0 || - slapi_pblock_set(pb, SLAPI_PLUGIN_BE_PRE_CLOSE_FN, (void *)cl5Close) != 0 || + slapi_pblock_set(pb, SLAPI_PLUGIN_BE_PRE_CLOSE_FN, (void *)cl5Cleanup) != 0 || slapi_pblock_set(pb, SLAPI_PLUGIN_BE_PRE_BACKUP_FN, (void *)cl5WriteRUV) != 0) { slapi_log_err(SLAPI_LOG_PLUGIN, repl_plugin_name, "multimaster_bepreop_init - Failed\n"); rc = -1; diff --git a/ldap/servers/slapd/back-ldbm/db-bdb/bdb_layer.c b/ldap/servers/slapd/back-ldbm/db-bdb/bdb_layer.c index 712deef..51a2892 100644 --- a/ldap/servers/slapd/back-ldbm/db-bdb/bdb_layer.c +++ b/ldap/servers/slapd/back-ldbm/db-bdb/bdb_layer.c @@ -1293,6 +1293,14 @@ bdb_start(struct ldbminfo *li, int dbmode) return return_value; } + /* We need to free the memory to avoid a leak + * Also, we have to evaluate if the performance counter + * should be preserved or not for database restore. + * Look - https://pagure.io/389-ds-base/issue/51020 + */ + if (conf->perf_private) { + perfctrs_terminate(&conf->perf_private, pEnv->bdb_DB_ENV); + } /* Now open the performance counters stuff */ perfctrs_init(li, &(conf->perf_private)); if (getenv(TXN_TESTING)) {