Browse Source

Bug 690584 - #10691 ldbm_back_init() - fix coverity resource leak issues

https://bugzilla.redhat.com/show_bug.cgi?id=690584
Resolves: bug 690584
Bug Description: #10691 ldbm_back_init() - fix coverity resource leak issues
Reviewed by: nkinder (Thanks!)
Branch: master
Fix Description: do not return (or exit!) from ldbm_back_init() - just goto
fail and clean up the ldbm_instance upon error.
Platforms tested: RHEL6 x86_64
Flag Day: no
Doc impact: no
Rich Megginson 14 years ago
parent
commit
5b44581e0b
1 changed files with 12 additions and 8 deletions
  1. 12 8
      ldap/servers/slapd/back-ldbm/init.c

+ 12 - 8
ldap/servers/slapd/back-ldbm/init.c

@@ -123,7 +123,7 @@ ldbm_back_init( Slapi_PBlock *pb )
 	/* initialize dblayer  */
 	if (dblayer_init(li)) {
 		LDAPDebug( LDAP_DEBUG_ANY, "ldbm_back_init: dblayer_init failed\n",0, 0, 0 );
-		return (-1);
+		goto fail;
 	}
 
 	/* Fill in the fields of the ldbminfo and the dblayer_private
@@ -138,7 +138,7 @@ ldbm_back_init( Slapi_PBlock *pb )
             &li->li_bulk_import_object, &li->li_bulk_import_handle) != 0) {
             LDAPDebug(LDAP_DEBUG_ANY, "ldbm_back_init: "
                       "slapi_register_object_extension failed.\n", 0, 0, 0);
-            return (-1);
+            goto fail;
         }
 
 	/* add some private attributes */
@@ -150,24 +150,24 @@ ldbm_back_init( Slapi_PBlock *pb )
 	if ((li->li_dbcache_mutex = PR_NewLock()) == NULL ) {
             LDAPDebug( LDAP_DEBUG_ANY, "ldbm_back_init: PR_NewLock failed\n",
 		0, 0, 0 );
-            return(-1);
+            goto fail;
         }
 
 	if ((li->li_shutdown_mutex = PR_NewLock()) == NULL ) {
             LDAPDebug( LDAP_DEBUG_ANY, "ldbm_back_init: PR_NewLock failed\n",
 		0, 0, 0 );
-            return(-1);
+            goto fail;
         }
 
 	if ((li->li_config_mutex = PR_NewLock()) == NULL ) {
             LDAPDebug( LDAP_DEBUG_ANY, "ldbm_back_init: PR_NewLock failed\n",
 		0, 0, 0 );
-            return(-1);
+            goto fail;
         }
 
 	if ((li->li_dbcache_cv = PR_NewCondVar( li->li_dbcache_mutex )) == NULL ) {
             LDAPDebug( LDAP_DEBUG_ANY, "ldbm_back_init: PR_NewCondVar failed\n", 0, 0, 0 );
-            exit(-1);
+            goto fail;
         }
 
 	/* set all of the necessary database plugin callback functions */
@@ -255,7 +255,7 @@ ldbm_back_init( Slapi_PBlock *pb )
 
 	if ( rc != 0 ) {
 		LDAPDebug( LDAP_DEBUG_ANY, "ldbm_back_init failed\n", 0, 0, 0 );
-		return( -1 );
+		goto fail;
 	}
 	
 	/* register the IDL interface with the API broker */
@@ -268,7 +268,7 @@ ldbm_back_init( Slapi_PBlock *pb )
 		if( slapi_apib_register(IDL_v1_0_GUID, IDL_api) )
 		{
 			LDAPDebug( LDAP_DEBUG_ANY, "ldbm_back_init: failed to publish IDL interface\n", 0, 0, 0);
-			return( -1 );
+			goto fail;
 		}
 
 		interface_published = 1;
@@ -277,6 +277,10 @@ ldbm_back_init( Slapi_PBlock *pb )
 	LDAPDebug( LDAP_DEBUG_TRACE, "<= ldbm_back_init\n", 0, 0, 0 );
 
 	return( 0 );
+
+fail:
+	dblayer_terminate( li );
+	return( -1 );
 }