Browse Source

Bug 630092 - (cov#12116) Resource leak in ldclt code

There is a chance that we leak the memory pointed to by the new
variable if we never have one of the ldclt contexts point to it.
We need to jump to the error label in this case to free the memory.
Nathan Kinder 15 years ago
parent
commit
e1702b5a04
1 changed files with 13 additions and 5 deletions
  1. 13 5
      ldap/servers/slapd/tools/ldclt/scalab01.c

+ 13 - 5
ldap/servers/slapd/tools/ldclt/scalab01.c

@@ -465,6 +465,13 @@ scalab01_addLogin (
     else
     {
       cur = s1ctx.list;
+
+      /* If cur is NULL, we should just bail and free new. */
+      if (cur == NULL)
+      {
+        goto error;
+      }
+
       while (cur != NULL)
       {
 	if (cur->next == NULL)
@@ -472,15 +479,16 @@ scalab01_addLogin (
 	  cur->next = new;
 	  cur       = NULL; /* Exit loop */
 	}
-	else
-	  if (cur->next->counter >= duration)
-	  {
+	else if (cur->next->counter >= duration)
+	{
 	    new->next = cur->next;
 	    cur->next = new;
 	    cur       = NULL; /* Exit loop */
-	  }
-	  else
+	}
+	else
+	{
 	    cur = cur->next;
+	}
       }
     }
   }