Fix memory leak and dubious list manipulation. (Found by Ron Koerner,
authorOwen Taylor <otaylor@redhat.com>
Thu, 19 Jul 2001 20:17:03 +0000 (20:17 +0000)
committerOwen Taylor <otaylor@src.gnome.org>
Thu, 19 Jul 2001 20:17:03 +0000 (20:17 +0000)
Thu Jul 19 16:05:21 2001  Owen Taylor  <otaylor@redhat.com>

* glib/gcompletion.c (g_completion_complete): Fix memory
leak and dubious list manipulation. (Found by
Ron Koerner, #53408)

* glib/gfileutils.c (get_contents_stdio): Call fclose()
on FILE * on error. (#57057)

glib/gcompletion.c
glib/gfileutils.c

index 1e882dc..9a33ff5 100644 (file)
@@ -182,16 +182,14 @@ g_completion_complete (GCompletion* cmp,
          list = cmp->cache;
          while (list)
            {
+             GList *next = list->next;
+             
              if (cmp->strncmp_func (prefix,
-                          cmp->func ? cmp->func (list->data) : (gchar*) list->data,
-                          len))
-               {
-                 list = g_list_remove_link (cmp->cache, list);
-                 if (list != cmp->cache)
-                   cmp->cache = list;
-               }
-             else
-               list = list->next;
+                                    cmp->func ? cmp->func (list->data) : (gchar*) list->data,
+                                    len))
+               cmp->cache = g_list_delete_link (cmp->cache, list);
+
+             list = next;
            }
          done = TRUE;
        }
index 9936867..031cbde 100644 (file)
@@ -309,6 +309,7 @@ get_contents_stdio (const gchar *filename,
                        filename, strerror (errno));
 
           g_string_free (str, TRUE);
+         fclose (f);
           
           return FALSE;
         }