diff options
| author | Endi S. Dewata <edewata@redhat.com> | 2010-07-26 11:49:16 -0500 |
|---|---|---|
| committer | Noriko Hosoi <nhosoi@redhat.com> | 2010-08-19 17:00:59 -0700 |
| commit | 2ab53b6abef228c3e656c4e9c13074c2e20939b3 (patch) | |
| tree | 237c53b31a73bd7cc3f171b04622780443d3b456 | |
| parent | cfe6c5216b13307a9f751f60d779276dff63b042 (diff) | |
Bug 617630 - fix coverify Defect Type: Resource leaks issues CID 12052 - 12093
https://bugzilla.redhat.com/show_bug.cgi?id=617630
Resolves: bug 617630
Bug description: fix coverify Defect Type: Resource leaks issues CID 12079.
description: ldbm_instance_create() has been modified to release inst when an error occurs.
| -rw-r--r-- | ldap/servers/slapd/back-ldbm/instance.c | 31 |
1 files changed, 22 insertions, 9 deletions
diff --git a/ldap/servers/slapd/back-ldbm/instance.c b/ldap/servers/slapd/back-ldbm/instance.c index 1b76b834..da66565b 100644 --- a/ldap/servers/slapd/back-ldbm/instance.c +++ b/ldap/servers/slapd/back-ldbm/instance.c @@ -53,7 +53,8 @@ static void ldbm_instance_destructor(void **arg); int ldbm_instance_create(backend *be, char *name) { struct ldbminfo *li = (struct ldbminfo *) be->be_database->plg_private; - ldbm_instance *inst; + ldbm_instance *inst = NULL; + int rc = 0; /* Allocate storage for the ldbm_instance structure. Information specific * to this instance of the ldbm backend will be held here. */ @@ -67,7 +68,8 @@ int ldbm_instance_create(backend *be, char *name) DEFAULT_CACHE_ENTRIES, CACHE_TYPE_ENTRY)) { LDAPDebug(LDAP_DEBUG_ANY, "ldbm_instance_create: cache_init failed\n", 0, 0, 0); - return -1; + rc = -1; + goto error; } /* @@ -79,7 +81,8 @@ int ldbm_instance_create(backend *be, char *name) DEFAULT_DNCACHE_MAXCOUNT, CACHE_TYPE_DN)) { LDAPDebug0Args(LDAP_DEBUG_ANY, "ldbm_instance_create: dn cache_init failed\n"); - return -1; + rc = -1; + goto error; } /* Lock for the list of open db handles */ @@ -87,7 +90,8 @@ int ldbm_instance_create(backend *be, char *name) if (NULL == inst->inst_handle_list_mutex) { LDAPDebug(LDAP_DEBUG_ANY, "ldbm_instance_create: PR_NewLock failed\n", 0, 0, 0); - return -1; + rc = -1; + goto error; } /* Lock used to synchronize modify operations. */ @@ -95,24 +99,28 @@ int ldbm_instance_create(backend *be, char *name) if (NULL == inst->inst_db_mutex) { LDAPDebug(LDAP_DEBUG_ANY, "ldbm_instance_create: PR_NewLock failed\n", 0, 0, 0); - return -1; + rc = -1; + goto error; } if ((inst->inst_config_mutex = PR_NewLock()) == NULL) { LDAPDebug(LDAP_DEBUG_ANY, "ldbm_instance_create: PR_NewLock failed\n", 0, 0, 0); - return -1; + rc = -1; + goto error; } if ((inst->inst_nextid_mutex = PR_NewLock()) == NULL) { LDAPDebug(LDAP_DEBUG_ANY, "ldbm_instance_create: PR_NewLock failed\n", 0, 0, 0); - return -1; + rc = -1; + goto error; } if ((inst->inst_indexer_cv = PR_NewCondVar(inst->inst_nextid_mutex)) == NULL) { LDAPDebug(LDAP_DEBUG_ANY, "ldbm_instance_create: PR_NewCondVar failed\n", 0, 0, 0 ); - return -1; + rc = -1; + goto error; } inst->inst_be = be; @@ -130,8 +138,13 @@ int ldbm_instance_create(backend *be, char *name) objset_add_obj(li->li_instance_set, instance_obj); object_release(instance_obj); } + goto done; - return 0; +error: + slapi_ch_free((void**)&inst); + +done: + return rc; } /* create the default indexes separately |
