gnumeric r16283 - in branches/gnumeric-1-8: . src



Author: mortenw
Date: Wed Jan 16 15:22:09 2008
New Revision: 16283
URL: http://svn.gnome.org/viewvc/gnumeric?rev=16283&view=rev

Log:
2008-01-16  Morten Welinder  <terra gnome org>

	* src/stf-parse.c (stf_parse_csv_line): Allocate from the string
	chunk so we don't leak items.  Reduce the number of GString
	allocations while we're at it.



Modified:
   branches/gnumeric-1-8/ChangeLog
   branches/gnumeric-1-8/NEWS
   branches/gnumeric-1-8/src/stf-parse.c

Modified: branches/gnumeric-1-8/NEWS
==============================================================================
--- branches/gnumeric-1-8/NEWS	(original)
+++ branches/gnumeric-1-8/NEWS	Wed Jan 16 15:22:09 2008
@@ -6,6 +6,7 @@
 	* Fix DSUM crash.  [#509427] 
 	* Fix insert-current-date locale problem.  [#508237]
 	* Fix xls read crash.  [#505330]
+	* Plug csv leak.
 
 --------------------------------------------------------------------------
 Gnumeric 1.8.0

Modified: branches/gnumeric-1-8/src/stf-parse.c
==============================================================================
--- branches/gnumeric-1-8/src/stf-parse.c	(original)
+++ branches/gnumeric-1-8/src/stf-parse.c	Wed Jan 16 15:22:09 2008
@@ -679,6 +679,7 @@
 {
 	GPtrArray *line;
 	gboolean cont = FALSE;
+	GString *text;
 
 	g_return_val_if_fail (src != NULL, NULL);
 	g_return_val_if_fail (parseoptions != NULL, NULL);
@@ -687,27 +688,32 @@
 	if (parseoptions->trim_seps)
 		stf_parse_eat_separators (src, parseoptions);
 
+	text = g_string_sized_new (30);
+
 	while (1) {
-		GString *text = g_string_sized_new (30);
+		char *ctext;
 		StfParseCellRes res =
 			stf_parse_csv_cell (text, src, parseoptions);
 		trim_spaces_inplace (text->str, parseoptions);
+		ctext = g_string_chunk_insert_len (src->chunk,
+						   text->str, text->len);
+		g_string_truncate (text, 0);
+
 		switch (res) {
 		case STF_CELL_FIELD_NO_SEP:
-			g_ptr_array_add (line, g_string_free (text, FALSE));
+			g_ptr_array_add (line, ctext);
 			cont = FALSE;
 			break;
 
 		case STF_CELL_FIELD_SEP:
-			g_ptr_array_add (line, g_string_free (text, FALSE));
+			g_ptr_array_add (line, ctext);
 			cont = TRUE;  /* Make sure we see one more field.  */
 			break;
 
 		default:
 			if (cont)
-				g_ptr_array_add (line, g_string_free (text, FALSE));
-			else
-				g_string_free (text, TRUE);
+				g_ptr_array_add (line, ctext);
+			g_string_free (text, TRUE);
 			return line;
 		}
 	}



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]