Fix a mem leak on an error path in OBJ_NAME_add()
authorMatt Caswell <matt@openssl.org>
Mon, 9 May 2016 16:44:26 +0000 (17:44 +0100)
committerMatt Caswell <matt@openssl.org>
Mon, 23 May 2016 23:12:04 +0000 (00:12 +0100)
If lh_OBJ_NAME_insert() fails then the allocated |onp| value is leaked.

RT#2238

Reviewed-by: Richard Levitte <levitte@openssl.org>
(cherry picked from commit 0a618df059d93bf7fe9e3ec92e04db8bc1eeff07)

crypto/objects/o_names.c

index 24859926ace6d9b79f8bf198c18610215e561812..f106905ffa77f45832f6026a8f87e79e5ff4a881 100644 (file)
@@ -191,7 +191,7 @@ int OBJ_NAME_add(const char *name, int type, const char *data)
     onp = (OBJ_NAME *)OPENSSL_malloc(sizeof(OBJ_NAME));
     if (onp == NULL) {
         /* ERROR */
-        return (0);
+        return 0;
     }
 
     onp->name = name;
@@ -216,10 +216,11 @@ int OBJ_NAME_add(const char *name, int type, const char *data)
     } else {
         if (lh_OBJ_NAME_error(names_lh)) {
             /* ERROR */
-            return (0);
+            OPENSSL_free(onp);
+            return 0;
         }
     }
-    return (1);
+    return 1;
 }
 
 int OBJ_NAME_remove(const char *name, int type)