From: Paul J. Reder Date: Fri, 30 Nov 2007 00:18:26 +0000 (+0000) Subject: Do a better job of checking managing memory during subgroup processing. X-Git-Tag: 2.3.0~1199 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f591ec6b8d4901139981b4a4bebee22fd5d60a70;p=apache Do a better job of checking managing memory during subgroup processing. Try to be graceful and harmless in cases where we run out of SHM. git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@599654 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/modules/ldap/util_ldap_cache_mgr.c b/modules/ldap/util_ldap_cache_mgr.c index 0942cc48b8..13d824532b 100644 --- a/modules/ldap/util_ldap_cache_mgr.c +++ b/modules/ldap/util_ldap_cache_mgr.c @@ -145,14 +145,32 @@ util_compare_subgroup_t *util_ald_sgl_dup(util_ald_cache_t *cache, util_compare_ int i = 0; util_compare_subgroup_t *sgl_out = NULL; - if (!sgl_in) return NULL; + if (!sgl_in) { + return NULL; + } sgl_out = (util_compare_subgroup_t *) util_ald_alloc(cache, sizeof(util_compare_subgroup_t)); - sgl_out->subgroupDNs = util_ald_alloc(cache, sizeof(char *) * sgl_in->len); - sgl_out->len = sgl_in->len; - - for (i = 0; i < sgl_in->len; i++) { - sgl_out->subgroupDNs[i] = util_ald_strdup(cache, sgl_in->subgroupDNs[i]); + if (sgl_out) { + sgl_out->subgroupDNs = util_ald_alloc(cache, sizeof(char *) * sgl_in->len); + if (sgl_out->subgroupDNs) { + for (i = 0; i < sgl_in->len; i++) { + sgl_out->subgroupDNs[i] = util_ald_strdup(cache, sgl_in->subgroupDNs[i]); + if (!sgl_out->subgroupDNs[i]) { + /* We ran out of SHM, delete the strings we allocated for the SGL */ + for (i = (i - 1); i >= 0; i--) { + util_ald_free(cache, sgl_out->subgroupDNs[i]); + } + util_ald_free(cache, sgl_out->subgroupDNs); + util_ald_free(cache, sgl_out); + sgl_out = NULL; + break; + } + } + /* We were able to allocate new strings for all the subgroups */ + if (sgl_out != NULL) { + sgl_out->len = sgl_in->len; + } + } } return sgl_out;