[Date Prev][Date Next] [Thread Prev][Thread Next]
[Thread Index]
[Date Index]
[Author Index]
Re: Memory leak in g_string_sized_new()?
- From: Charles Schmidt <cschmidt2 emich edu>
- To: rroth uiuc edu
- Cc: gtk-app-devel-list gnome org
- Subject: Re: Memory leak in g_string_sized_new()?
- Date: Tue, 21 Jan 2003 02:32:27 -0600
Ronald Roth wrote:
> #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;
> }
The first GString you create, with g_string_new(NULL) is never free'd.
This code shouldn't (but I havn't tested it) leak:
#include <glib.h>
#include <stdio.h>
int main() {
GString *temp1,*temp2;
int size=5;
temp1=g_string_new(NULL);
printf("About to allocate string\n");
getchar();
temp2=g_string_sized_new(size);
getchar();
printf("temp size: %i alloc:%i\n", temp2->len,
temp2->allocated_len);
printf("About to free string.\n");
getchar();
g_string_free(temp1, TRUE);
g_string_free(temp2,TRUE);
return 0;
}
Hope this helps
--
-charlie
[Date Prev][Date Next] [Thread Prev][Thread Next]
[Thread Index]
[Date Index]
[Author Index]