AndrewBelt / osdialog

A cross platform wrapper for OS dialogs like file save, open, message boxes, inputs, color picking, etc.
Creative Commons Zero v1.0 Universal
122 stars 19 forks source link

osdialog_gtk2.c mixes std allocation and gtk allocation #4

Closed RicoP closed 5 years ago

RicoP commented 5 years ago

I saw that in osdialog_gtk2.c we return a string that is allocated with gtk_file_chooser_get_filename

    char *result = NULL;
    if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) {
        result = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
    }

when we return this string directly we are in danger that on a later point we might try to deallocate the result with std::free.

The problem is that gtk uses it's own memory management, and mixing g_malloc and regular free leads to issues.

I would recommend copying the result string with strdup and deallocating the previous string with g_free before returning.

Also see: https://mail.gnome.org/archives/gtk-list/2000-July/msg00002.html

AndrewBelt commented 5 years ago

Thanks, fixed in 65a3b2e