From a47bf6ed4f186f41693e186bf107cf51ada4d5ae Mon Sep 17 00:00:00 2001 From: "B. Watson" Date: Wed, 10 Jan 2024 13:46:06 -0500 Subject: Clean up memory leak when changing window size. --- hcalc.h | 3 ++- input.c | 2 +- setupx.c | 8 +++++++- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/hcalc.h b/hcalc.h index f04d0a9..44d4cc0 100644 --- a/hcalc.h +++ b/hcalc.h @@ -53,9 +53,10 @@ void button(int b, int x, int y); void complete_paste(unsigned char *s, int n); void send_current_display(void); void setup_x(void); +void shutdown_x(void); void free_pixmaps(void); void load_pixmaps(void); -void process_input(); +void process_input(void); void load_config(void); void save_config(void); void show_value(void); diff --git a/input.c b/input.c index ba15f07..561b97e 100644 --- a/input.c +++ b/input.c @@ -433,7 +433,7 @@ void key(char c) { winsize++; if(winsize == 3) winsize = 0; free_pixmaps(); - XCloseDisplay(display); + shutdown_x(); setup_x(); load_pixmaps(); show_value(); diff --git a/setupx.c b/setupx.c index 4f4f583..c103f64 100644 --- a/setupx.c +++ b/setupx.c @@ -92,7 +92,13 @@ void setup_x(void) { bit_off = color.pixel; } -void process_input() { +void shutdown_x(void) { + XDestroyWindow(display, window); + XFreeGC(display, gc); + XCloseDisplay(display); +} + +void process_input(void) { char c; KeySym keysym; XTextProperty tprop; -- cgit v1.2.3