From 54ec43e2c88e2adc4908a46ebf8770b1b134161e Mon Sep 17 00:00:00 2001 From: "Endi S. Dewata" Date: Sun, 18 Jul 2010 17:25:08 -0500 Subject: Bug 616500 - fix coverify Defect Type: Resource leaks issues CID 12094 - 12136 https://bugzilla.redhat.com/show_bug.cgi?id=616500 Resolves: bug 616500 Bug description: fix coverify Defect Type: Resource leaks issues CID 12114 description: Fixed resource leaks in buildNewModAttribFile(). --- ldap/servers/slapd/tools/ldclt/ldapfct.c | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/ldap/servers/slapd/tools/ldclt/ldapfct.c b/ldap/servers/slapd/tools/ldclt/ldapfct.c index 658d71d5..aeecf4b9 100644 --- a/ldap/servers/slapd/tools/ldclt/ldapfct.c +++ b/ldap/servers/slapd/tools/ldclt/ldapfct.c @@ -1525,9 +1525,11 @@ buildNewModAttribFile ( LDAPMod attribute; /* To build the attributes */ struct berval *bv = malloc(sizeof(struct berval)); attribute.mod_bvalues = (struct berval **)malloc(2 * sizeof(struct berval *)); + int rc = 0; if ((bv == NULL) || (attribute.mod_bvalues == NULL)) { - return -1; + rc = -1; + goto error; } /* @@ -1536,8 +1538,11 @@ buildNewModAttribFile ( * to build the rdn of the new entry. * Note that the random new attribute is also build by this function. */ - if (buildRandomRdnOrFilter (tttctx) < 0) - return (-1); + if (buildRandomRdnOrFilter (tttctx) < 0) { + rc = -1; + goto error; + } + strcpy (newDn, tttctx->bufFilter); strcat (newDn, ","); strcat (newDn, tttctx->bufBaseDN); @@ -1554,9 +1559,22 @@ buildNewModAttribFile ( attribute.mod_bvalues[0] = bv; attribute.mod_bvalues[1] = NULL; - if (addAttrib (attrs, nbAttribs++, &attribute) < 0) - return (-1); + if (addAttrib (attrs, nbAttribs++, &attribute) < 0) { + rc = -1; + goto error; + } + + goto done; + +error: + if (bv != NULL) { + free(bv); + } + if (attribute.mod_bvalues != NULL) { + free(attribute.mod_bvalues); + } +done: /* * Normal end */ -- cgit