[MPlayer-cvslog] r34767 - trunk/gui/util/list.c

ib subversion at mplayerhq.hu
Thu Feb 23 14:07:50 CET 2012


Author: ib
Date: Thu Feb 23 14:07:49 2012
New Revision: 34767

Log:
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.

Modified:
   trunk/gui/util/list.c

Modified: trunk/gui/util/list.c
==============================================================================
--- trunk/gui/util/list.c	Thu Feb 23 13:59:28 2012	(r34766)
+++ trunk/gui/util/list.c	Thu Feb 23 14:07:49 2012	(r34767)
@@ -31,7 +31,6 @@ void *listMgr(int cmd, void *data)
 {
     plItem *pdat  = (plItem *)data;
     urlItem *udat = (urlItem *)data;
-    int is_added  = 1;
 
     switch (cmd) {
     // playlist
@@ -146,26 +145,31 @@ void *listMgr(int cmd, void *data)
         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;
-                    break;
+            while (item) {
+                if (strcmp(udat->url, item->url) == 0) {
+                    free(udat->url);
+                    free(udat);
+                    return NULL;
                 }
 
-                item = item->next;
+                if (item->next)
+                    item = item->next;
+                else {
+                    item->next = udat;
+                    udat->next = NULL;
+                    break;
+                }
             }
-
-            if (!is_added && gstrcmp(item->url, udat->url))
-                item->next = udat;
         } else {
             udat->next = NULL;
             urlList    = udat;
         }
-        return NULL;
+
+        return udat;
 
     case URLLIST_DELETE:
 


More information about the MPlayer-cvslog mailing list