aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorNathan Williams <njw@chromium.org>2011-09-27 13:40:39 -0500
committerDan Williams <dcbw@redhat.com>2011-09-27 13:40:39 -0500
commit8710820156f51d1861b329e6fc12e706304ddda9 (patch)
tree21fd334c5023fc0aa15a4023b5b10177a6e51ba4 /src
parent00670456ffb4b08af3620a95c73601bc15d84eb9 (diff)
core: ensure that GMatchInfo and GRegex objects are freed properly
In particular, g_regex_match() and g_regex_match_full() allocate a match_info structure on both success and failure, so calling g_match_info_free() only in the success case is insufficient. BUG=None TEST=Inspection Change-Id: Iea76b5b5dc3ec48120e15601a5e2dd45322133d8
Diffstat (limited to 'src')
-rw-r--r--src/mm-generic-gsm.c33
-rw-r--r--src/mm-modem-helpers.c15
-rw-r--r--src/mm-serial-parsers.c32
3 files changed, 37 insertions, 43 deletions
diff --git a/src/mm-generic-gsm.c b/src/mm-generic-gsm.c
index 78703042..82e51f67 100644
--- a/src/mm-generic-gsm.c
+++ b/src/mm-generic-gsm.c
@@ -2860,7 +2860,7 @@ handle_reg_status_response (MMGenericGsm *self,
guint32 status = 0;
gulong lac = 0, ci = 0;
gint act = -1;
- gboolean cgreg = FALSE;
+ gboolean cgreg = FALSE, parsed;
guint i;
/* Try to match the response */
@@ -2880,22 +2880,21 @@ handle_reg_status_response (MMGenericGsm *self,
}
/* And parse it */
- if (!mm_gsm_parse_creg_response (match_info, &status, &lac, &ci, &act, &cgreg, error)) {
- g_match_info_free (match_info);
- return FALSE;
- }
+ parsed = mm_gsm_parse_creg_response (match_info, &status, &lac, &ci, &act, &cgreg, error);
+ g_match_info_free (match_info);
+ if (parsed) {
+ /* Success; update cached location information */
+ update_lac_ci (self, lac, ci, cgreg ? 1 : 0);
- /* Success; update cached location information */
- update_lac_ci (self, lac, ci, cgreg ? 1 : 0);
-
- /* Only update access technology if it appeared in the CREG/CGREG response */
- if (act != -1)
- mm_generic_gsm_update_access_technology (self, etsi_act_to_mm_act (act));
+ /* Only update access technology if it appeared in the CREG/CGREG response */
+ if (act != -1)
+ mm_generic_gsm_update_access_technology (self, etsi_act_to_mm_act (act));
- /* Update cached registration status */
- reg_status_updated (self, cgreg_to_reg_type (cgreg), status, NULL);
+ /* Update cached registration status */
+ reg_status_updated (self, cgreg_to_reg_type (cgreg), status, NULL);
+ }
- return TRUE;
+ return parsed;
}
#define CS_ERROR_TAG "cs-error"
@@ -3619,9 +3618,13 @@ cid_range_read (MMAtSerialPort *port,
g_match_info_next (match_info, NULL);
}
- if (cid == 0)
+ if (cid == 0) {
/* Choose something */
cid = 1;
+ }
+
+ g_match_info_free (match_info);
+ g_regex_unref (r);
}
} else
info->error = g_error_new_literal (MM_MODEM_ERROR,
diff --git a/src/mm-modem-helpers.c b/src/mm-modem-helpers.c
index f6a0ffa3..66c3fb64 100644
--- a/src/mm-modem-helpers.c
+++ b/src/mm-modem-helpers.c
@@ -125,10 +125,8 @@ mm_gsm_parse_scan_response (const char *reply, GError **error)
/* If we didn't get any hits, try the pre-UMTS format match */
if (!g_regex_match (r, reply, 0, &match_info)) {
g_regex_unref (r);
- if (match_info) {
- g_match_info_free (match_info);
- match_info = NULL;
- }
+ g_match_info_free (match_info);
+ match_info = NULL;
/* Pre-UMTS format doesn't include the cell access technology after
* the numeric operator element.
@@ -778,8 +776,8 @@ mm_gsm_parse_cscs_support_response (const char *reply,
g_match_info_next (match_info, NULL);
success = TRUE;
}
- g_match_info_free (match_info);
}
+ g_match_info_free (match_info);
g_regex_unref (r);
if (success)
@@ -1020,8 +1018,8 @@ mm_parse_cind_test_response (const char *reply, GError **error)
g_match_info_next (match_info, NULL);
}
- g_match_info_free (match_info);
}
+ g_match_info_free (match_info);
g_regex_unref (r);
return hash;
@@ -1086,11 +1084,10 @@ mm_parse_cind_query_response(const char *reply, GError **error)
g_free (str);
g_match_info_next (match_info, NULL);
}
- g_match_info_free (match_info);
done:
- if (r)
- g_regex_unref (r);
+ g_match_info_free (match_info);
+ g_regex_unref (r);
return array;
}
diff --git a/src/mm-serial-parsers.c b/src/mm-serial-parsers.c
index 344e1bc7..f94e1156 100644
--- a/src/mm-serial-parsers.c
+++ b/src/mm-serial-parsers.c
@@ -125,8 +125,6 @@ mm_serial_parser_v0_parse (gpointer data,
} else
code = MM_MOBILE_ERROR_UNKNOWN;
- g_match_info_free (match_info);
-
switch (code) {
case 0: /* OK */
break;
@@ -155,9 +153,10 @@ mm_serial_parser_v0_parse (gpointer data,
remove_matches (parser->generic_response, response);
}
+ g_match_info_free (match_info);
+
if (!found) {
found = g_regex_match_full (parser->detailed_error, response->str, response->len, 0, 0, &match_info, NULL);
-
if (found) {
str = g_match_info_fetch (match_info, 1);
if (str) {
@@ -166,9 +165,9 @@ mm_serial_parser_v0_parse (gpointer data,
} else
code = MM_MOBILE_ERROR_UNKNOWN;
- g_match_info_free (match_info);
local_error = mm_mobile_error_for_code (code);
}
+ g_match_info_free (match_info);
}
if (found)
@@ -260,7 +259,7 @@ mm_serial_parser_v1_parse (gpointer data,
GMatchInfo *match_info;
GError *local_error = NULL;
gboolean found = FALSE;
- char *str;
+ char *str = NULL;
int code;
g_return_val_if_fail (parser != NULL, FALSE);
@@ -306,10 +305,9 @@ mm_serial_parser_v1_parse (gpointer data,
str = g_match_info_fetch (match_info, 1);
g_assert (str);
local_error = mm_mobile_error_for_code (atoi (str));
- g_free (str);
- g_match_info_free (match_info);
goto done;
}
+ g_match_info_free (match_info);
}
/* Numeric CME errors */
@@ -320,10 +318,9 @@ mm_serial_parser_v1_parse (gpointer data,
str = g_match_info_fetch (match_info, 1);
g_assert (str);
local_error = mm_mobile_error_for_code (atoi (str));
- g_free (str);
- g_match_info_free (match_info);
goto done;
}
+ g_match_info_free (match_info);
/* Numeric CMS errors */
/* Todo
@@ -337,10 +334,9 @@ mm_serial_parser_v1_parse (gpointer data,
str = g_match_info_fetch (match_info, 1);
g_assert (str);
local_error = mm_mobile_error_for_code (atoi (str));
- g_free (str);
- g_match_info_free (match_info);
goto done;
}
+ g_match_info_free (match_info);
/* String CME errors */
found = g_regex_match_full (parser->regex_cme_error_str,
@@ -350,10 +346,9 @@ mm_serial_parser_v1_parse (gpointer data,
str = g_match_info_fetch (match_info, 1);
g_assert (str);
local_error = mm_mobile_error_for_string (str);
- g_free (str);
- g_match_info_free (match_info);
goto done;
}
+ g_match_info_free (match_info);
/* Motorola EZX errors */
found = g_regex_match_full (parser->regex_ezx_error,
@@ -363,19 +358,19 @@ mm_serial_parser_v1_parse (gpointer data,
str = g_match_info_fetch (match_info, 1);
g_assert (str);
local_error = mm_mobile_error_for_code (MM_MOBILE_ERROR_UNKNOWN);
- g_free (str);
- g_match_info_free (match_info);
goto done;
}
+ g_match_info_free (match_info);
/* Last resort; unknown error */
found = g_regex_match_full (parser->regex_unknown_error,
response->str, response->len,
- 0, 0, NULL, NULL);
+ 0, 0, &match_info, NULL);
if (found) {
local_error = mm_mobile_error_for_code (MM_MOBILE_ERROR_UNKNOWN);
goto done;
}
+ g_match_info_free (match_info);
/* Connection failures */
found = g_regex_match_full (parser->regex_connect_failed,
@@ -398,13 +393,12 @@ mm_serial_parser_v1_parse (gpointer data,
code = MM_MODEM_CONNECT_ERROR_NO_CARRIER;
}
- g_free (str);
- g_match_info_free (match_info);
-
local_error = mm_modem_connect_error_for_code (code);
}
done:
+ g_free (str);
+ g_match_info_free (match_info);
if (found)
response_clean (response);