1 From 1d200a63ac4e39035af35e80881aa4fdae5556c6 Mon Sep 17 00:00:00 2001
2 From: Christian Persch <chpe@src.gnome.org>
3 Date: Sat, 18 Nov 2017 18:40:03 +0100
4 Subject: matcher: Fix memory leak
5
6 Don't leak the GValueArray.
7
8 https://bugzilla.gnome.org/show_bug.cgi?id=790539
9 (cherry picked from commit dda73cc07250ea324b4227907197c39b93fcd365)
10 ---
11 src/matcher.cc | 12 +++++++-----
12 src/table.cc | 19 +++++++++++--------
13 2 files changed, 18 insertions(+), 13 deletions(-)
14
15 diff --git a/src/matcher.cc b/src/matcher.cc
16 index 10f3bc7..a4f7584 100644
17 --- a/src/matcher.cc
18 +++ b/src/matcher.cc
19 @@ -202,14 +202,16 @@ _vte_matcher_print(struct _vte_matcher *matcher)
20 * we need to free those ourselves. */
21 void
22 _vte_matcher_free_params_array(struct _vte_matcher *matcher,
23 - GValueArray *params)
24 + GValueArray *params)
25 {
26 guint i;
27 for (i = 0; i < params->n_values; i++) {
28 - GValue *value = ¶ms->values[i];
29 - if (G_UNLIKELY (g_type_is_a (value->g_type, G_TYPE_POINTER))) {
30 - g_free (g_value_get_pointer (value));
31 - }
32 + auto value = g_value_array_get_nth(params, i);
33 + if (G_UNLIKELY (G_VALUE_HOLDS_POINTER(value))) {
34 + g_free(g_value_get_pointer(value));
35 + } else if (G_UNLIKELY (G_VALUE_HOLDS_BOXED(value))) {
36 + g_value_array_free((GValueArray*)g_value_get_boxed(value));
37 + }
38 }
39 if (G_UNLIKELY (matcher == NULL || matcher->free_params != NULL)) {
40 g_value_array_free (params);
41 diff --git a/src/table.cc b/src/table.cc
42 index 3c78f3a..09a6172 100644
43 --- a/src/table.cc
44 +++ b/src/table.cc
45 @@ -516,18 +516,14 @@ static void
46 _vte_table_extract_numbers(GValueArray **array,
47 struct _vte_table_arginfo *arginfo)
48 {
49 - GValue value = {0,};
50 - GValue subvalue = {0,};
51 - GValueArray *subarray = NULL;
52 - gssize i;
53 -
54 if (G_UNLIKELY (*array == NULL)) {
55 *array = g_value_array_new(1);
56 }
57
58 + GValue value = {0,};
59 g_value_init(&value, G_TYPE_LONG);
60 - g_value_init(&subvalue, G_TYPE_VALUE_ARRAY);
61 - i = 0;
62 + gssize i = 0;
63 + GValueArray *subarray = nullptr;
64 do {
65 long total = 0;
66 for (; i < arginfo->length && arginfo->start[i] != ';' && arginfo->start[i] != ':'; i++) {
67 @@ -546,13 +542,20 @@ _vte_table_extract_numbers(GValueArray **array,
68 g_value_array_append(*array, &value);
69 } else {
70 g_value_array_append(subarray, &value);
71 - g_value_set_boxed(&subvalue, subarray);
72 +
73 + GValue subvalue = {0,};
74 + g_value_init(&subvalue, G_TYPE_VALUE_ARRAY);
75 + g_value_take_boxed(&subvalue, subarray);
76 g_value_array_append(*array, &subvalue);
77 + g_value_unset(&subvalue);
78 +
79 subarray = NULL;
80 }
81 }
82 } while (i++ < arginfo->length);
83 g_value_unset(&value);
84 + if (subarray != nullptr)
85 + g_value_array_free(subarray);
86 }
87
88 static void
89 --
90 cgit v0.12
|