[Xfce4-commits] r25942 - xarchiver/trunk/src

Giuseppe Torelli colossus at xfce.org
Tue Jul 31 11:13:57 CEST 2007


Author: colossus
Date: 2007-07-31 09:13:57 +0000 (Tue, 31 Jul 2007)
New Revision: 25942

Modified:
   xarchiver/trunk/src/archive.c
   xarchiver/trunk/src/archive.h
   xarchiver/trunk/src/string_utils.c
   xarchiver/trunk/src/zip.c
Log:
All the archive entries are now freed.
Fixed a memory leak in string_utils.c.
Fixed missed count of content size in zip.c


Modified: xarchiver/trunk/src/archive.c
===================================================================
--- xarchiver/trunk/src/archive.c	2007-07-30 21:17:32 UTC (rev 25941)
+++ xarchiver/trunk/src/archive.c	2007-07-31 09:13:57 UTC (rev 25942)
@@ -159,14 +159,24 @@
 
 void xa_clean_archive_structure (XArchive *archive)
 {
+	GSList *s = NULL;
 	gchar *dummy_string;
 	gchar *msg;
 	int response;
+	unsigned short int i;
+	XEntry *entry;
+	gpointer current_column;
 
 	if (archive == NULL)
 		return;
 
-	//TODO: to free entry, g_hash_table,entries
+	s = archive->entries;
+	for (; s; s = s->next)
+	{
+		entry = s->data;
+		xa_free_entry (archive,entry);
+	}
+	
 	if (archive->column_types != NULL)
 		g_free(archive->column_types);
 
@@ -287,6 +297,38 @@
 	return entry;
 }
 
+void xa_free_entry (XArchive *archive,XEntry *entry)
+{
+	gpointer current_column;
+	unsigned short int i;
+
+	if (entry->child)
+		xa_free_entry(archive,entry->child);
+
+	if (entry->next)
+		xa_free_entry(archive,entry->next);
+
+	current_column = entry->columns;
+
+	for (i = 0; i < archive->nc; i++)
+	{
+		switch(archive->column_types[i+2])
+		{
+			case G_TYPE_STRING:
+				g_free (*((gchar **)current_column));
+				current_column += sizeof(gchar *);
+			break;
+
+			case G_TYPE_UINT64:
+				current_column += sizeof(guint64);
+			break;
+		}
+	}
+	g_free(entry->columns);
+	g_free(entry->filename);
+	g_free(entry);
+}
+
 XEntry *xa_find_archive_entry(XEntry *entry, gchar *string)
 {
 	if (entry == NULL)

Modified: xarchiver/trunk/src/archive.h
===================================================================
--- xarchiver/trunk/src/archive.h	2007-07-30 21:17:32 UTC (rev 25941)
+++ xarchiver/trunk/src/archive.h	2007-07-31 09:13:57 UTC (rev 25942)
@@ -124,6 +124,7 @@
 gint xa_get_new_archive_idx();
 //gint xa_read_line (XArchive *archive, FILE *stream, gchar **return_string);
 XEntry *xa_alloc_memory_for_each_row ( guint nc,GType column_types[]);
+void xa_free_entry (XArchive *archive,XEntry *entry);
 XEntry *xa_find_archive_entry(XEntry *entry, gchar *string);
 XEntry *xa_set_archive_entries_for_each_row (XArchive *archive,gchar *filename,gpointer *items);
 gpointer *xa_fill_archive_entry_columns_for_each_row (XArchive *archive,XEntry *entry,gpointer *items);

Modified: xarchiver/trunk/src/string_utils.c
===================================================================
--- xarchiver/trunk/src/string_utils.c	2007-07-30 21:17:32 UTC (rev 25941)
+++ xarchiver/trunk/src/string_utils.c	2007-07-31 09:13:57 UTC (rev 25942)
@@ -298,10 +298,10 @@
 	else
 		retval = g_strndup(first_slash, (second_slash - first_slash) );
 
-	g_free (reverse);
 	g_strreverse(retval);
 
 here:
+	g_free (reverse);
 	return retval;
 }
 

Modified: xarchiver/trunk/src/zip.c
===================================================================
--- xarchiver/trunk/src/zip.c	2007-07-30 21:17:32 UTC (rev 25941)
+++ xarchiver/trunk/src/zip.c	2007-07-31 09:13:57 UTC (rev 25942)
@@ -112,6 +112,7 @@
 
 	line[n]='\0';
 	item[i] = line + a;
+	archive->dummy_size += strtoll(item[i],NULL,0);
 	i++;
 	n++;
 



More information about the Xfce4-commits mailing list