Code

liboconfig/oconfig.c: Free all allocated memory in oconfig_free().
[collectd.git] / src / liboconfig / oconfig.c
index 2bb80cc99a864b6112dd065048221310b8ca3211..db9285b3cf47052581405dcfce2d69170d0c587f 100644 (file)
@@ -76,11 +76,25 @@ void oconfig_free (oconfig_item_t *ci)
 {
   int i;
 
+  if (ci == NULL)
+    return;
+
+  if (ci->key != NULL)
+    free (ci->key);
+
+  for (i = 0; i < ci->values_num; i++)
+    if ((ci->values[i].type == OCONFIG_TYPE_STRING)
+        && (NULL != ci->values[i].value.string))
+      free (ci->values[i].value.string);
+
   if (ci->values != NULL)
     free (ci->values);
 
   for (i = 0; i < ci->children_num; i++)
     oconfig_free (ci->children + i);
+
+  if (ci->children != NULL)
+    free (ci->children);
 }
 
 /*