From 891138a30ed9a5f9cdd221c00d2b650594abe9c9 Mon Sep 17 00:00:00 2001 From: Thierry Bordaz Date: Oct 08 2019 09:49:24 +0000 Subject: Bug 1750893: Memory leak when slapi-nis return entries retrieved from nsswitch When slapi-nis retrieves the entries added by nsswitch search it fills 'staged' structures. Those structures should be freed once the entries have been returned https://bugzilla.redhat.com/show_bug.cgi?id=1750893 --- diff --git a/src/back-sch.c b/src/back-sch.c index 87fa24c..ae8f96b 100644 --- a/src/back-sch.c +++ b/src/back-sch.c @@ -1649,6 +1649,45 @@ backend_send_mapped_entries(struct backend_search_cbdata *cbdata) cbdata->entries_tail = NULL; } +static void +backend_search_free_staged(struct backend_search_cbdata *cbdata) +{ + struct backend_staged_search *staged, *next; + int i; + int nb_entries = 0; + int nb_stages = 0; + + if (cbdata == NULL) { + return; + } + + staged = cbdata->staged; + while (staged != NULL) { + nb_stages++; + for (i = 0; + (i < staged->count) && + (staged->entries != NULL) && + (staged->entries[i] != NULL); + i++) { + slapi_entry_free(staged->entries[i]); + staged->entries[i] = NULL; + } + nb_entries += i; + slapi_ch_free_string(&staged->map_group); + slapi_ch_free_string(&staged->map_set); + slapi_ch_free_string(&staged->name); + slapi_ch_free_string(&staged->container_sdn); + next = staged->next; + free(staged); + staged = next; + } + slapi_log_error(SLAPI_LOG_PLUGIN, + cbdata->state->plugin_desc->spd_id, + "backend_search_free_staged freed %d stages with %d entries\n", + nb_stages, + nb_entries); + cbdata->staged = NULL; +} static int backend_search_cb(Slapi_PBlock *pb) { @@ -1853,6 +1892,7 @@ backend_search_cb(Slapi_PBlock *pb) map_unlock(); /* Return newly acquired entries */ backend_send_mapped_entries(&cbdata); + backend_search_free_staged(&cbdata); } else { slapi_log_error(SLAPI_LOG_PLUGIN, cbdata.state->plugin_desc->spd_id,