Browse Source

Bug 697027 - 12 - minor memory leaks found by Valgrind + TET

https://bugzilla.redhat.com/show_bug.cgi?id=697027
[Case 12]
Description: The caller of valuearray_remove_value is responsible
for freeing the removed value.  Adding slapi_value_free to free it.
Noriko Hosoi 14 years ago
parent
commit
e227048e66
1 changed files with 6 additions and 1 deletions
  1. 6 1
      ldap/servers/slapd/valueset.c

+ 6 - 1
ldap/servers/slapd/valueset.c

@@ -399,6 +399,7 @@ valuearray_remove_value_atindex(Slapi_Value **va, int index)
  * Find the value in the array,
  * shunt up the array to cover it,
  * return a ptr to the value.
+ * The caller is responsible for freeing the value.
  */
 Slapi_Value *
 valuearray_remove_value(const Slapi_Attr *a, Slapi_Value **va, const Slapi_Value *v)
@@ -1043,9 +1044,13 @@ void
 valueset_remove_string(const Slapi_Attr *a, Slapi_ValueSet *vs, const char *s)
 {
 	Slapi_Value v;
+	Slapi_Value *removed;
 	value_init(&v,NULL,CSN_TYPE_NONE,NULL);
 	slapi_value_set_string(&v,s);
-    valuearray_remove_value(a,vs->va,&v);
+	removed = valuearray_remove_value(a, vs->va, &v);
+	if(removed) {
+		slapi_value_free(&removed);
+	}
 	value_done(&v);
 }