Complete.Org: Mailing Lists: Archives: freeciv-dev: June 2004:
[Freeciv-Dev] (PR#9036) registry memory leak
Home

[Freeciv-Dev] (PR#9036) registry memory leak

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: undisclosed-recipients: ;
Subject: [Freeciv-Dev] (PR#9036) registry memory leak
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Sat, 19 Jun 2004 17:43:11 -0700
Reply-to: rt@xxxxxxxxxxx

<URL: http://rt.freeciv.org/Ticket/Display.html?id=9036 >

==2141== 3945 bytes in 263 blocks are definitely lost in loss record 19 
of 22
==2141==    at 0x3C01F40D: malloc (vg_replace_malloc.c:105)
==2141==    by 0x804D56A: fc_real_realloc (mem.c:58)
==2141==    by 0x804D389: astr_minsize (astring.c:82)
==2141==    by 0x80B84E7: section_file_read_dup (registry.c:520)
==2141==    by 0x80B7DBD: section_file_load (registry.c:584)
==2141==    by 0x808EBF1: openload_ruleset_file (ruleset.c:157)
==2141==    by 0x808E98A: load_rulesets (ruleset.c:3173)
==2141==    by 0x804FA77: srv_loop (srv_main.c:1567)
==2141==    by 0x804F219: srv_main (srv_main.c:1521)
==2141==    by 0x804A3CC: main (civserver.c:161)

This is an astring_vector, that is a "vector" of astrings.  The vector 
size changes.  When it grows, new astrings are allocated.  But when it 
shrinks the excess astrings are not removed.  The result is that these 
extra strings are lost.  This is similar to what vasco did in the 
citydlg.  Perhaps the design should be changed but that's more bugprone.

However the fix is easy.

jason

Index: utility/registry.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/utility/registry.c,v
retrieving revision 1.63
diff -u -r1.63 registry.c
--- utility/registry.c  17 May 2004 19:43:28 -0000      1.63
+++ utility/registry.c  20 Jun 2004 00:41:02 -0000
@@ -512,6 +512,9 @@
        {       /* expand columns: */
          int j, n_prev;
          n_prev = astring_vector_size(&columns);
+         for (j = i + 1; j < n_prev; j++) {
+           astr_free(&columns.p[j]);
+         }
          astring_vector_reserve(&columns, i + 1);
          for (j = n_prev; j < i + 1; j++) {
            astr_init(&columns.p[j]);

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] (PR#9036) registry memory leak, Jason Short <=