changeset 34679:6378e3a2ffb8

Revise listMgr() command URLLIST_ITEM_ADD. Remove unnecessary variable is_added, replace gstrcmp() by strcmp(), fix memory leakage by freeing list item that won't be added and change return value to pointer to added item. Additionally, insert some blank lines.
author ib
date Thu, 23 Feb 2012 13:07:49 +0000
parents 23f4f2104774
children f49f6501eb8b
files gui/util/list.c
diffstat 1 files changed, 15 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/gui/util/list.c	Thu Feb 23 12:59:28 2012 +0000
+++ b/gui/util/list.c	Thu Feb 23 13:07:49 2012 +0000
@@ -31,7 +31,6 @@
 {
     plItem *pdat  = (plItem *)data;
     urlItem *udat = (urlItem *)data;
-    int is_added  = 1;
 
     switch (cmd) {
     // playlist
@@ -146,26 +145,31 @@
         return urlList;
 
     case URLLIST_ITEM_ADD:
+
         if (urlList) {
             urlItem *item = urlList;
-            is_added = 0;
 
-            while (item->next) {
-                if (!gstrcmp(item->url, udat->url)) {
-                    is_added = 1;
+            while (item) {
+                if (strcmp(udat->url, item->url) == 0) {
+                    free(udat->url);
+                    free(udat);
+                    return NULL;
+                }
+
+                if (item->next)
+                    item = item->next;
+                else {
+                    item->next = udat;
+                    udat->next = NULL;
                     break;
                 }
-
-                item = item->next;
             }
-
-            if (!is_added && gstrcmp(item->url, udat->url))
-                item->next = udat;
         } else {
             udat->next = NULL;
             urlList    = udat;
         }
-        return NULL;
+
+        return udat;
 
     case URLLIST_DELETE: