Question

My code:

char* fileName;    
fileName=g_filename_from_utf8(gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog)),-1,NULL,NULL,NULL);

The string returned from gtk_file_chooser_get_filename() cannot be referenced, so it can't be freed. Is this a memory leak? Should I assign it to an identifier and then free() it instead of passing it directly to g_filename_from_utf8()?

Was it helpful?

Solution

Yes, this will be a memory leak. You have to free it using g_free() as noted here

Also you have to check for NULL as gtk_file_chooser_get_filename could return NULL on error as well.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top