我正在尝试释放GString *
使用g_string_free
,指针是使用分配的g_string_sized_new
。但是 valgrind 也会导致内存泄漏。
示例代码:
Ports * function(bs_t *bs)
{
GString *string = g_string_sized_new(PATH_MAX);
char template[] = "/tmp/grokXXXXXX";
Ports *rc =NULL;
if (condition) {
rc = (Ports *) malloc (sizeof(Ports));
if (rc == NULL) {
g_string_free(string, TRUE);
return NULL;
}
}
if (condition_2) {
if (!port_file(string->str, &rc->ports[0], &rc->port_valid,
NUM_RC_PORTS))
{
g_free(rc);
rc=NULL;
}
}
g_string_free(string, TRUE);
return rc;
}