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

Log:
2008-01-16  Morten Welinder  <[EMAIL PROTECTED]>

        * 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:
   trunk/ChangeLog
   trunk/NEWS
   trunk/src/stf-parse.c

Modified: trunk/NEWS
==============================================================================
--- trunk/NEWS  (original)
+++ trunk/NEWS  Wed Jan 16 15:21:20 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: trunk/src/stf-parse.c
==============================================================================
--- trunk/src/stf-parse.c       (original)
+++ trunk/src/stf-parse.c       Wed Jan 16 15:21:20 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;
                }
        }
_______________________________________________
SVN-commits-list mailing list (read only)
http://mail.gnome.org/mailman/listinfo/svn-commits-list

Want to limit the commits to a few modules? Go to above URL, log in to edit 
your options and select the modules ('topics') you want.
Module maintainer? It is possible to set the reply-to to your development 
mailing list. Email [EMAIL PROTECTED] if interested.

Reply via email to