On 01/31/2012 07:06 PM, Eduardo Lima (Etrunko) wrote:
From: "Eduardo Lima (Etrunko)" <eblima(a)br.ibm.com>
Signed-off-by: Eduardo Lima (Etrunko) <eblima(a)br.ibm.com>
---
libxkutil/acl_parsing.c | 58 +++++++++-------------------------
libxkutil/acl_parsing.h | 5 ++-
libxkutil/xmlgen.c | 30 +++++++++++++----
src/Virt_NestedFilterList.c | 73 +++++++++++++++++++++++-------------------
4 files changed, 81 insertions(+), 85 deletions(-)
diff --git a/libxkutil/acl_parsing.c b/libxkutil/acl_parsing.c
index 9c4b4b2..f7efcfc 100644
--- a/libxkutil/acl_parsing.c
+++ b/libxkutil/acl_parsing.c
@@ -141,11 +141,7 @@ void cleanup_filter(struct acl_filter *filter)
free(filter->rules);
filter->rule_ct = 0;
- for (i = 0; i < filter->ref_ct; i++)
- free(filter->refs[i]);
-
- free(filter->refs);
- filter->ref_ct = 0;
+ list_free(filter->refs);
}
void cleanup_filters(struct acl_filter **filters, int count)
@@ -610,58 +606,34 @@ int append_filter_rule(struct acl_filter *filter, struct acl_rule
*rule)
return 1;
}
-int append_filter_ref(struct acl_filter *filter, char *name)
-{
- int i;
- char **old_refs = NULL;
-
- if ((filter == NULL) || (name == NULL))
- return 0;
-
- for (i = 0; i < filter->ref_ct; i++)
- if (STREQC(filter->refs[i], name))
- return 0; /* already exists */
-
- old_refs = filter->refs;
- filter->refs = malloc((filter->ref_ct + 1) * sizeof(char *));
+static int filter_ref_cmp(void *list_data, void *user_data)
+{
+ return strcmp((const char *)list_data, (const char *) user_data);
+}
- if (filter->refs == NULL) {
- CU_DEBUG("Failed to allocate memory for new ref");
- filter->refs = old_refs;
+int append_filter_ref(struct acl_filter *filter, char *name)
+{
+ if (filter == NULL || name == NULL)
return 0;
- }
- memcpy(filter->refs, old_refs, filter->ref_ct * sizeof(char *));
+ if (filter->refs == NULL)
+ filter->refs = list_new(free, filter_ref_cmp);
- filter->refs[filter->ref_ct] = name;
- filter->ref_ct++;
+ if (list_find(filter->refs, name) != NULL)
+ return 0; /* already exists */
Here we leak the name var.
--
Eduardo de Barros Lima
Software Engineer, Open Virtualization
Linux Technology Center - IBM/Brazil
eblima(a)br.ibm.com