andykimpe / rpms / 389-ds-base

Forked from rpms/389-ds-base 5 months ago
Clone
Blob Blame History Raw
From a9787f2d1b1ab7a477a22acb8a5e22193f2b4dca Mon Sep 17 00:00:00 2001
From: Noriko Hosoi <nhosoi@totoro.usersys.redhat.com>
Date: Wed, 26 Sep 2012 16:55:39 -0700
Subject: [PATCH 290/305] Coverity defects

13093: Resource leak
Fix description: If udn is allocated in ndn_cache_lookup and it
has no chance to be consumed in ndn_cache_add, udn is released.

(cherry picked from commit 4754fb7da3066119576a115a04470b91c4184257)

Conflicts:
	ldap/servers/slapd/dn.c

(cherry picked from commit c49b03070c275575ba879e4e9cee98fc038ce7e6)
---
 ldap/servers/slapd/dn.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/ldap/servers/slapd/dn.c b/ldap/servers/slapd/dn.c
index 53c378a..9c1084f 100644
--- a/ldap/servers/slapd/dn.c
+++ b/ldap/servers/slapd/dn.c
@@ -535,7 +535,7 @@ slapi_dn_normalize_ext(char *src, size_t src_len, char **dest, size_t *dest_len)
     char *ends = NULL;
     char *endd = NULL;
     char *lastesc = NULL;
-    char *udn;
+    char *udn = NULL;
     /* rdn avs for the main DN */
     char *typestart = NULL;
     int rdn_av_count = 0;
@@ -1130,8 +1130,13 @@ bail:
         *d = '\0';
     }
     /* add this dn to the normalized dn cache */
-    if(*dest)
-        ndn_cache_add(udn, src_len, *dest, *dest_len);
+    if (udn) {
+        if(dest && *dest && dest_len && *dest_len) {
+            ndn_cache_add(udn, src_len, *dest, *dest_len);
+        } else {
+            slapi_ch_free_string(&udn);
+        }
+    }
 
     return rc;
 }
@@ -2774,6 +2779,10 @@ ndn_cache_lookup(char *dn, size_t dn_len, char **result, char **udn, int *rc)
     char *ndn, *key;
     int rv = 0;
 
+    if(NULL == udn){
+        return rv;
+    }
+    *udn = NULL;
     if(ndn_started == 0){
         return rv;
     }
-- 
1.9.3