Memory leak in g_string_sized_new()?
- From: Ronald Roth <rroth uiuc edu>
- To: GTK App Devel List <gtk-app-devel-list gnome org>
- Subject: Memory leak in g_string_sized_new()?
- Date: Tue, 21 Jan 2003 01:20:11 -0600 (CST)
Hi, all
While hunting for mem leaks in my program, I noticed that memprof was
reporting that a call to g_string_sized_new(str_size) was returning a
string whose "allocated_len" field was HALF of the amount of memory that
memprof said was allocated in that call. Then, upon calling g_string_free
on the same string, with free_segment=TRUE, only "allocated_len" bytes were
free. So, I can see no way to free the remaining memory! Has anyone else
experienced this? I can reproduce the problem on my computer with the
following test program, using memprof and noting the total allocated bytes
between the getchar() function calls.
#include <glib.h>
#include <stdio.h>
int main() {
GString *temp;
int size=5;
temp=g_string_new(NULL);
printf("About to allocate string\n");
getchar();
temp=g_string_sized_new(size);
getchar();
printf("temp size: %i alloc:%i\n", temp->len, temp->allocated_len);
printf("About to free string.\n");
getchar();
g_string_free(temp, TRUE);
return 0;
}
When I run this with "memprof ./test" I get the following results:
At the first getchar() call: Memprof reports 2236 bytes allocated.
Second getchar() call: 2252 bytes (Just called g_string_sized_new()) 16
bytes were allocated. (presumably to the GString "temp")
Third getchar() call: 2252 bytes, program reports temp->allocated_len=8.
Fourth getchar() call: 2244 bytes, (just called g_string_free()) 8 bytes
were freed.
As you can see, 8 bytes got leaked. Could someone explain what is going
on? Have I found a bug? Or am I fooling myself? Or is memprof lying to me?
I have glib version 2.0.7.
Thanks!
-Ron Roth
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]