Skip to content

Commit

Permalink
Clean memory
Browse files Browse the repository at this point in the history
Signed-off-by: Thibault Meyer <[email protected]>
  • Loading branch information
thibaultmeyer committed Jan 18, 2020
1 parent 6d3c387 commit ce47801
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/gui/gui_main_callback_header_bar_load_rom.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ void gui_main_callback_header_bar_load_rom(GtkApplication *app, gpointer user_da
break;
}
default:
// Stop emulation
gui_emulation_timer_stop();

// Use newly created CPU instance
if (gl_gui_components.chip8_cpu) {
chip8_free_cpu(gl_gui_components.chip8_cpu);
Expand All @@ -92,6 +95,9 @@ void gui_main_callback_header_bar_load_rom(GtkApplication *app, gpointer user_da
gchar *basename = g_filename_display_basename(filename);
gtk_header_bar_set_subtitle(GTK_HEADER_BAR(gl_gui_components.gtk_header_bar), basename);
g_free(basename);

// Start emulation
gui_emulation_timer_start();
break;
}

Expand Down
10 changes: 9 additions & 1 deletion src/gui/gui_main_callback_window_destroy.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
#include "gui.h"

void gui_main_callback_window_destroy(GtkWidget *widget, gpointer data) {
// Stop emulation
gui_emulation_timer_stop();
gtk_widget_destroy(widget);

// Free allocated global variables
gtk_widget_destroy(gl_gui_components.gtk_header_bar);
gtk_widget_destroy(gl_gui_components.gtk_drawing_area);
gtk_widget_destroy(widget); // gl_gui_components.gtk_window

// Free CPU
chip8_free_cpu(gl_gui_components.chip8_cpu);
}

0 comments on commit ce47801

Please sign in to comment.