]> granicus.if.org Git - apache/commitdiff
Do a better job of checking managing memory during subgroup processing.
authorPaul J. Reder <rederpj@apache.org>
Fri, 30 Nov 2007 00:18:26 +0000 (00:18 +0000)
committerPaul J. Reder <rederpj@apache.org>
Fri, 30 Nov 2007 00:18:26 +0000 (00:18 +0000)
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

modules/ldap/util_ldap_cache_mgr.c

index 0942cc48b8e692ef92571c345448f9760cd5749d..13d824532b004bdb90a5c75360dd691efc21dd22 100644 (file)
@@ -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;