문제

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()?

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top