Skip to content

Commit

Permalink
debugger: Consolidate code for selecting the target file
Browse files Browse the repository at this point in the history
This fixes a leak, a possible NULL-pointer dereference and buffer
overflows.
  • Loading branch information
b4n committed Oct 25, 2014
1 parent 0a61a76 commit b7b4677
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions debugger/src/tpage.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,10 @@ static void on_arguments_changed(GtkTextBuffer *textbuffer, gpointer user_data)
*/
static void on_target_browse_clicked(GtkButton *button, gpointer user_data)
{
gchar path[FILENAME_MAX];
gchar *path;
const gchar *prevfile;
gchar *prevdir;
GtkWidget *dialog;
GeanyDocument *doc;

dialog = gtk_file_chooser_dialog_new (_("Choose target file"),
NULL,
Expand All @@ -110,14 +110,15 @@ static void on_target_browse_clicked(GtkButton *button, gpointer user_data)
NULL);

prevfile = gtk_entry_get_text(GTK_ENTRY(target_name));
prevdir = g_path_get_dirname(prevfile);
if (strcmp(".", prevdir))
strcpy(path, prevdir);
else
strcpy(path, g_path_get_dirname(DOC_FILENAME(document_get_current())));
g_free(prevdir);
path = g_path_get_dirname(prevfile);
if (strcmp(".", path) == 0 && (doc = document_get_current()) != NULL)
{
g_free(path);
path = g_path_get_dirname(DOC_FILENAME(doc));
}

gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER (dialog), path);
g_free(path);

if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT)
{
Expand Down

0 comments on commit b7b4677

Please sign in to comment.