From 24669a81f28667db46bed174ab26118eb87fd4e4 Mon Sep 17 00:00:00 2001 From: Perry Werneck Date: Wed, 10 Jul 2019 16:41:09 -0300 Subject: [PATCH] Fixing valgrind's detections. --- src/dialogs/colorscheme.c | 16 ++++++++++++---- src/include/v3270.h | 1 + src/terminal/font.c | 10 +++++++++- src/terminal/widget.c | 19 +++++++++++++++---- src/trace/widget.c | 2 ++ valgrind.suppression | 41 +++++++++++++++++++++++++++++++++++++++++ 6 files changed, 80 insertions(+), 9 deletions(-) diff --git a/src/dialogs/colorscheme.c b/src/dialogs/colorscheme.c index ed6ec2e..2777202 100644 --- a/src/dialogs/colorscheme.c +++ b/src/dialogs/colorscheme.c @@ -126,8 +126,8 @@ static void load_color_scheme(GKeyFile *conf, const gchar *group, GdkRGBA *clr) { - const gchar * val; - size_t f; + gchar * val; + size_t f; // Load base colors val = g_key_file_get_string(conf,group,"base",NULL); @@ -165,7 +165,7 @@ } g_strfreev(str); - + g_free(val); } else { @@ -194,6 +194,7 @@ gdk_rgba_parse(clr+V3270_COLOR_FIELD+f,str[f]); g_strfreev(str); + g_free(val); } // Load selection colors @@ -208,6 +209,7 @@ gdk_rgba_parse(clr+V3270_COLOR_SELECTED_BG+f,str[f]); g_strfreev(str); + g_free(val); } // Load OIA colors @@ -243,6 +245,7 @@ } g_strfreev(str); + g_free(val); } // Setup extended elements @@ -250,7 +253,10 @@ val = g_key_file_get_string(conf,group,"cross-hair",NULL); if(val) + { gdk_rgba_parse(clr+V3270_COLOR_CROSS_HAIR,val); + g_free(val); + } } @@ -297,7 +303,7 @@ { // Setup colors for current entry GdkRGBA * clr = GTK_V3270_COLOR_SCHEME(widget)->schemes+index; - const gchar * label = g_key_file_get_locale_string(conf,group[g],"label",NULL,NULL); + gchar * label = g_key_file_get_locale_string(conf,group[g],"label",NULL,NULL); load_color_scheme(conf,group[g],clr); @@ -308,6 +314,8 @@ 1, clr, -1); + g_free(label); + // move to next color list index += V3270_COLOR_COUNT; } diff --git a/src/include/v3270.h b/src/include/v3270.h index f8feb77..9c50fa9 100644 --- a/src/include/v3270.h +++ b/src/include/v3270.h @@ -78,6 +78,7 @@ guint top; gchar * family; + cairo_font_face_t * face; cairo_font_weight_t weight; cairo_scaled_font_t * scaled; diff --git a/src/terminal/font.c b/src/terminal/font.c index b6c8404..0704ea8 100644 --- a/src/terminal/font.c +++ b/src/terminal/font.c @@ -79,7 +79,15 @@ void v3270_update_font_metrics(v3270 *terminal, cairo_t *cr, unsigned int width, terminal->font.weight = lib3270_get_toggle(terminal->host,LIB3270_TOGGLE_BOLD) ? CAIRO_FONT_WEIGHT_BOLD : CAIRO_FONT_WEIGHT_NORMAL; - cairo_select_font_face(cr,terminal->font.family, CAIRO_FONT_SLANT_NORMAL,terminal->font.weight); + if(terminal->font.face) + { + cairo_font_face_destroy(terminal->font.face); + } + + terminal->font.face = cairo_toy_font_face_create(terminal->font.family, CAIRO_FONT_SLANT_NORMAL, terminal->font.weight); + cairo_set_font_face(cr,terminal->font.face); + + // cairo_select_font_face(cr,terminal->font.family, CAIRO_FONT_SLANT_NORMAL,terminal->font.weight); if(terminal->font.scaled) { diff --git a/src/terminal/widget.c b/src/terminal/widget.c index aafd8b3..0f72e3c 100644 --- a/src/terminal/widget.c +++ b/src/terminal/widget.c @@ -232,6 +232,16 @@ static void v3270_toggle_changed(G_GNUC_UNUSED v3270 *widget, G_GNUC_UNUSED LIB3 static void finalize(GObject *object) { debug("V3270::%s",__FUNCTION__); + + v3270 * terminal = GTK_V3270(object); + + if(terminal->host) + { + // Release session + lib3270_session_free(terminal->host); + terminal->host = NULL; + } + G_OBJECT_CLASS(v3270_parent_class)->finalize(object); } @@ -579,10 +589,6 @@ static void v3270_destroy(GtkWidget *widget) // Cleanup lib3270_reset_callbacks(terminal->host); lib3270_set_user_data(terminal->host,NULL); - - // Release session - lib3270_session_free(terminal->host); - terminal->host = NULL; } if(terminal->accessible) @@ -604,6 +610,11 @@ static void v3270_destroy(GtkWidget *widget) terminal->font.scaled = NULL; } + if(terminal->font.face) { + cairo_font_face_destroy(terminal->font.face); + terminal->font.face = NULL; + } + if(terminal->surface) { cairo_surface_destroy(terminal->surface); diff --git a/src/trace/widget.c b/src/trace/widget.c index 7b8b267..52c837a 100644 --- a/src/trace/widget.c +++ b/src/trace/widget.c @@ -110,6 +110,8 @@ if(widget->hSession == hSession) return; + debug("%s: Session changes %p -> %p", __FUNCTION__, widget->hSession, hSession); + if(widget->hSession) { lib3270_set_trace_handler(widget->hSession,widget->trace.handler,widget->trace.userdata); } diff --git a/valgrind.suppression b/valgrind.suppression index 8129432..d65bea1 100644 --- a/valgrind.suppression +++ b/valgrind.suppression @@ -97,3 +97,44 @@ fun:g_type_create_instance } +{ + fontconfig_FcPatternDuplicate + Memcheck:Leak + ... + fun:FcPatternDuplicate +} + +{ + gtk_style_context_set_state + Memcheck:Leak + ... + fun:gtk_style_context_set_state +} + +{ + g_param_spec_flags + Memcheck:Leak + ... + fun:g_param_spec_flags +} + +{ + gtk_style_new + Memcheck:Leak + ... + fun:gtk_style_new +} + +{ + libcrypto_BIO_read + Memcheck:Cond + fun:BIO_read +} + +{ + cairo_mask + Memcheck:Cond + ... + fun:cairo_mask +} + -- libgit2 0.21.2