andykimpe / rpms / 389-ds-base

Forked from rpms/389-ds-base 5 months ago
Clone
Blob Blame History Raw
From 14b2dda6574c3358df4a5770de78eb96504200cd Mon Sep 17 00:00:00 2001
From: Noriko Hosoi <nhosoi@redhat.com>
Date: Mon, 10 Mar 2014 12:50:57 -0700
Subject: [PATCH 185/225] Ticket #47740 - Coverity issue in 1.3.3

Description: Coverity 11778 - Resource leak
val was allocated by dbconf_decodeval, which was not freed if propval
failed to create.

Reviewed by mareynol@redhat.com (Thanks, Mark!)
(cherry picked from commit 6f51e06c606049e7ca8e0b763c683fa98b33974a)
(cherry picked from commit f3afc1198c2d9d63d6b5ad01d3fe5b9061d648a1)
(cherry picked from commit cfb821cf44eee3fd977702e6a81267bac1f3625f)
(cherry picked from commit d8395ecd432fd68588992a954113bca23e48e99f)
---
 lib/ldaputil/dbconf.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/lib/ldaputil/dbconf.c b/lib/ldaputil/dbconf.c
index e6de3b7..1ffdab7 100644
--- a/lib/ldaputil/dbconf.c
+++ b/lib/ldaputil/dbconf.c
@@ -264,20 +264,20 @@ static int dbconf_parse_propval (char *buf, char *ptr,
     propval = (DBPropVal_t *)malloc(sizeof(DBPropVal_t));
 
     if (!propval){
-    	if (encval) free(val);
+        if (encval && val) free(val);
         return LDAPU_ERR_OUT_OF_MEMORY;
     }
     memset((void *)propval, 0, sizeof(DBPropVal_t));
     propval->prop = strdup(prop);
     propval->val = val ? strdup(val) : 0;
 
+    if (encval && val) free(val); /* val was allocated by dbconf_decodeval */
+
     if (!propval->prop || (val && !propval->val)) {
-	dbconf_free_propval(propval);
-	return LDAPU_ERR_OUT_OF_MEMORY;
+        dbconf_free_propval(propval);
+        return LDAPU_ERR_OUT_OF_MEMORY;
     }
 
-    if(encval) free(val);	/* val was allocated by dbconf_decodeval */
-
     insert_dbinfo_propval(db_info, propval);
     return LDAPU_SUCCESS;
 }
-- 
1.8.1.4