[PATCH v2 06/14] OdevAttribute: config_odev_add_attribute: replace existing values

Hans de Goede hdegoede at redhat.com
Tue Feb 4 12:49:12 CET 2014


If an attribute already exists replace its value rather then adding a
duplicate attribute with the new value to the list.

Signed-off-by: Hans de Goede <hdegoede at redhat.com>
---
 config/config.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/config/config.c b/config/config.c
index 64dfb88..aaef746 100644
--- a/config/config.c
+++ b/config/config.c
@@ -163,11 +163,14 @@ config_odev_add_attribute(struct OdevAttributes *attribs, int attrib,
 {
     struct OdevAttribute *oa;
 
-    oa = malloc(sizeof(struct OdevAttribute));
+    oa = config_odev_find_attribute(attribs, attrib);
+    if (!oa)
+        oa = calloc(1, sizeof(struct OdevAttribute));
     if (!oa)
         return FALSE;
 
     oa->attrib_id = attrib;
+    free(oa->attrib_name);
     oa->attrib_name = strdup(attrib_name);
     xorg_list_append(&oa->member, &attribs->list);
     return TRUE;
-- 
1.8.5.3



More information about the xorg-devel mailing list