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
This commit is contained in:
Nathan Williams
2011-09-27 13:40:39 -05:00
committed by Dan Williams
parent 00670456ff
commit 8710820156
11 changed files with 65 additions and 60 deletions

View File

@@ -183,6 +183,9 @@ evdo_state_done (MMAtSerialPort *port,
} }
} }
g_match_info_free (match_info);
g_regex_unref (r);
done: done:
mm_generic_cdma_query_reg_state_set_callback_evdo_state (info, reg_state); mm_generic_cdma_query_reg_state_set_callback_evdo_state (info, reg_state);
mm_callback_info_schedule (info); mm_callback_info_schedule (info);
@@ -254,6 +257,9 @@ state_done (MMAtSerialPort *port,
} }
} }
g_match_info_free (match_info);
g_regex_unref (r);
mm_generic_cdma_query_reg_state_set_callback_1x_state (info, reg_state); mm_generic_cdma_query_reg_state_set_callback_1x_state (info, reg_state);
/* Try for EVDO state too */ /* Try for EVDO state too */

View File

@@ -652,6 +652,9 @@ get_smong_cb (MMAtSerialPort *port,
priv->sind_psinfo = TRUE; priv->sind_psinfo = TRUE;
} }
g_match_info_free (match_info);
g_regex_unref (regex);
mm_callback_info_set_result (info, GUINT_TO_POINTER (act), NULL); mm_callback_info_set_result (info, GUINT_TO_POINTER (act), NULL);
mm_callback_info_schedule (info); mm_callback_info_schedule (info);
} }
@@ -698,12 +701,14 @@ get_sind_cb (MMAtSerialPort *port,
g_free (ind_value); g_free (ind_value);
mm_callback_info_set_result (info, GUINT_TO_POINTER (act), NULL); mm_callback_info_set_result (info, GUINT_TO_POINTER (act), NULL);
mm_callback_info_schedule (info); mm_callback_info_schedule (info);
return; } else {
/* If there was no 'psinfo' indicator, we'll try AT^SMONG and read the cell
* info table. */
mm_at_serial_port_queue_command (port, "^SMONG", 3, get_smong_cb, info);
} }
/* If there was no 'psinfo' indicator, we'll try AT^SMONG and read the cell g_match_info_free (match_info);
* info table. */ g_regex_unref (regex);
mm_at_serial_port_queue_command (port, "^SMONG", 3, get_smong_cb, info);
} }
static void static void

View File

@@ -599,9 +599,9 @@ send_huawei_cpin_done (MMAtSerialPort *port,
mm_callback_info_set_result (info, GUINT_TO_POINTER (attempts_left), NULL); mm_callback_info_set_result (info, GUINT_TO_POINTER (attempts_left), NULL);
g_match_info_free (match_info);
done: done:
if (match_info)
g_match_info_free (match_info);
if (r) if (r)
g_regex_unref (r); g_regex_unref (r);
mm_serial_port_close (MM_SERIAL_PORT (port)); mm_serial_port_close (MM_SERIAL_PORT (port));

View File

@@ -198,8 +198,6 @@ parse_nwrat_response (GString *response,
mode = atoi (str); mode = atoi (str);
g_free (str); g_free (str);
g_match_info_free (match_info);
if (mode < 0 || mode > 2) { if (mode < 0 || mode > 2) {
g_set_error_literal (error, MM_MODEM_ERROR, MM_MODEM_ERROR_GENERAL, g_set_error_literal (error, MM_MODEM_ERROR, MM_MODEM_ERROR_GENERAL,
"Failed to parse mode/tech response"); "Failed to parse mode/tech response");
@@ -219,6 +217,7 @@ parse_nwrat_response (GString *response,
success = TRUE; success = TRUE;
out: out:
g_match_info_free (match_info);
g_regex_unref (r); g_regex_unref (r);
return success; return success;
} }

View File

@@ -357,9 +357,9 @@ send_samsung_pinnum_done (MMAtSerialPort *port,
mm_callback_info_set_result (info, GUINT_TO_POINTER (attempts_left), NULL); mm_callback_info_set_result (info, GUINT_TO_POINTER (attempts_left), NULL);
g_match_info_free (match_info);
done: done:
if (match_info)
g_match_info_free (match_info);
if (r) if (r)
g_regex_unref (r); g_regex_unref (r);
mm_serial_port_close (MM_SERIAL_PORT (port)); mm_serial_port_close (MM_SERIAL_PORT (port));

View File

@@ -73,7 +73,7 @@ get_allowed_mode_done (MMAtSerialPort *port,
{ {
MMCallbackInfo *info = (MMCallbackInfo *) user_data; MMCallbackInfo *info = (MMCallbackInfo *) user_data;
GRegex *r = NULL; GRegex *r = NULL;
GMatchInfo *match_info; GMatchInfo *match_info = NULL;
/* If the modem has already been removed, return without /* If the modem has already been removed, return without
* scheduling callback */ * scheduling callback */
@@ -128,6 +128,8 @@ get_allowed_mode_done (MMAtSerialPort *port,
} }
done: done:
if (match_info)
g_match_info_free (match_info);
if (r) if (r)
g_regex_unref (r); g_regex_unref (r);
mm_callback_info_schedule (info); mm_callback_info_schedule (info);

View File

@@ -81,8 +81,6 @@ parse_syssel_response (GString *response,
mode = atoi (str); mode = atoi (str);
g_free (str); g_free (str);
g_match_info_free (match_info);
if (mode < 0 || mode > 2) { if (mode < 0 || mode > 2) {
g_set_error_literal (error, MM_MODEM_ERROR, MM_MODEM_ERROR_GENERAL, g_set_error_literal (error, MM_MODEM_ERROR, MM_MODEM_ERROR_GENERAL,
"Failed to parse mode/tech response"); "Failed to parse mode/tech response");
@@ -102,6 +100,7 @@ parse_syssel_response (GString *response,
success = TRUE; success = TRUE;
out: out:
g_match_info_free (match_info);
g_regex_unref (r); g_regex_unref (r);
return success; return success;
} }

View File

@@ -105,7 +105,7 @@ get_allowed_mode_done (MMAtSerialPort *port,
{ {
MMCallbackInfo *info = (MMCallbackInfo *) user_data; MMCallbackInfo *info = (MMCallbackInfo *) user_data;
GRegex *r = NULL; GRegex *r = NULL;
GMatchInfo *match_info; GMatchInfo *match_info = NULL;
/* If the modem has already been removed, return without /* If the modem has already been removed, return without
* scheduling callback */ * scheduling callback */
@@ -138,8 +138,6 @@ get_allowed_mode_done (MMAtSerialPort *port,
pref_acq = atoi (str); pref_acq = atoi (str);
g_free (str); g_free (str);
g_match_info_free (match_info);
if (cm_mode < 0 || cm_mode > 2 || pref_acq < 0 || pref_acq > 2) { if (cm_mode < 0 || cm_mode > 2 || pref_acq < 0 || pref_acq > 2) {
info->error = g_error_new (MM_MODEM_ERROR, info->error = g_error_new (MM_MODEM_ERROR,
MM_MODEM_ERROR_GENERAL, MM_MODEM_ERROR_GENERAL,
@@ -164,6 +162,8 @@ get_allowed_mode_done (MMAtSerialPort *port,
} }
done: done:
if (match_info)
g_match_info_free (match_info);
if (r) if (r)
g_regex_unref (r); g_regex_unref (r);
mm_callback_info_schedule (info); mm_callback_info_schedule (info);

View File

@@ -2860,7 +2860,7 @@ handle_reg_status_response (MMGenericGsm *self,
guint32 status = 0; guint32 status = 0;
gulong lac = 0, ci = 0; gulong lac = 0, ci = 0;
gint act = -1; gint act = -1;
gboolean cgreg = FALSE; gboolean cgreg = FALSE, parsed;
guint i; guint i;
/* Try to match the response */ /* Try to match the response */
@@ -2880,22 +2880,21 @@ handle_reg_status_response (MMGenericGsm *self,
} }
/* And parse it */ /* And parse it */
if (!mm_gsm_parse_creg_response (match_info, &status, &lac, &ci, &act, &cgreg, error)) { parsed = mm_gsm_parse_creg_response (match_info, &status, &lac, &ci, &act, &cgreg, error);
g_match_info_free (match_info); g_match_info_free (match_info);
return FALSE; if (parsed) {
/* 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));
/* Update cached registration status */
reg_status_updated (self, cgreg_to_reg_type (cgreg), status, NULL);
} }
/* Success; update cached location information */ return parsed;
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));
/* Update cached registration status */
reg_status_updated (self, cgreg_to_reg_type (cgreg), status, NULL);
return TRUE;
} }
#define CS_ERROR_TAG "cs-error" #define CS_ERROR_TAG "cs-error"
@@ -3619,9 +3618,13 @@ cid_range_read (MMAtSerialPort *port,
g_match_info_next (match_info, NULL); g_match_info_next (match_info, NULL);
} }
if (cid == 0) if (cid == 0) {
/* Choose something */ /* Choose something */
cid = 1; cid = 1;
}
g_match_info_free (match_info);
g_regex_unref (r);
} }
} else } else
info->error = g_error_new_literal (MM_MODEM_ERROR, info->error = g_error_new_literal (MM_MODEM_ERROR,

View File

@@ -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 we didn't get any hits, try the pre-UMTS format match */
if (!g_regex_match (r, reply, 0, &match_info)) { if (!g_regex_match (r, reply, 0, &match_info)) {
g_regex_unref (r); g_regex_unref (r);
if (match_info) { g_match_info_free (match_info);
g_match_info_free (match_info); match_info = NULL;
match_info = NULL;
}
/* Pre-UMTS format doesn't include the cell access technology after /* Pre-UMTS format doesn't include the cell access technology after
* the numeric operator element. * the numeric operator element.
@@ -778,8 +776,8 @@ mm_gsm_parse_cscs_support_response (const char *reply,
g_match_info_next (match_info, NULL); g_match_info_next (match_info, NULL);
success = TRUE; success = TRUE;
} }
g_match_info_free (match_info);
} }
g_match_info_free (match_info);
g_regex_unref (r); g_regex_unref (r);
if (success) 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_next (match_info, NULL);
} }
g_match_info_free (match_info);
} }
g_match_info_free (match_info);
g_regex_unref (r); g_regex_unref (r);
return hash; return hash;
@@ -1086,11 +1084,10 @@ mm_parse_cind_query_response(const char *reply, GError **error)
g_free (str); g_free (str);
g_match_info_next (match_info, NULL); g_match_info_next (match_info, NULL);
} }
g_match_info_free (match_info);
done: done:
if (r) g_match_info_free (match_info);
g_regex_unref (r); g_regex_unref (r);
return array; return array;
} }

View File

@@ -125,8 +125,6 @@ mm_serial_parser_v0_parse (gpointer data,
} else } else
code = MM_MOBILE_ERROR_UNKNOWN; code = MM_MOBILE_ERROR_UNKNOWN;
g_match_info_free (match_info);
switch (code) { switch (code) {
case 0: /* OK */ case 0: /* OK */
break; break;
@@ -155,9 +153,10 @@ mm_serial_parser_v0_parse (gpointer data,
remove_matches (parser->generic_response, response); remove_matches (parser->generic_response, response);
} }
g_match_info_free (match_info);
if (!found) { if (!found) {
found = g_regex_match_full (parser->detailed_error, response->str, response->len, 0, 0, &match_info, NULL); found = g_regex_match_full (parser->detailed_error, response->str, response->len, 0, 0, &match_info, NULL);
if (found) { if (found) {
str = g_match_info_fetch (match_info, 1); str = g_match_info_fetch (match_info, 1);
if (str) { if (str) {
@@ -166,9 +165,9 @@ mm_serial_parser_v0_parse (gpointer data,
} else } else
code = MM_MOBILE_ERROR_UNKNOWN; code = MM_MOBILE_ERROR_UNKNOWN;
g_match_info_free (match_info);
local_error = mm_mobile_error_for_code (code); local_error = mm_mobile_error_for_code (code);
} }
g_match_info_free (match_info);
} }
if (found) if (found)
@@ -260,7 +259,7 @@ mm_serial_parser_v1_parse (gpointer data,
GMatchInfo *match_info; GMatchInfo *match_info;
GError *local_error = NULL; GError *local_error = NULL;
gboolean found = FALSE; gboolean found = FALSE;
char *str; char *str = NULL;
int code; int code;
g_return_val_if_fail (parser != NULL, FALSE); 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); str = g_match_info_fetch (match_info, 1);
g_assert (str); g_assert (str);
local_error = mm_mobile_error_for_code (atoi (str)); local_error = mm_mobile_error_for_code (atoi (str));
g_free (str);
g_match_info_free (match_info);
goto done; goto done;
} }
g_match_info_free (match_info);
} }
/* Numeric CME errors */ /* Numeric CME errors */
@@ -320,10 +318,9 @@ mm_serial_parser_v1_parse (gpointer data,
str = g_match_info_fetch (match_info, 1); str = g_match_info_fetch (match_info, 1);
g_assert (str); g_assert (str);
local_error = mm_mobile_error_for_code (atoi (str)); local_error = mm_mobile_error_for_code (atoi (str));
g_free (str);
g_match_info_free (match_info);
goto done; goto done;
} }
g_match_info_free (match_info);
/* Numeric CMS errors */ /* Numeric CMS errors */
/* Todo /* Todo
@@ -337,10 +334,9 @@ mm_serial_parser_v1_parse (gpointer data,
str = g_match_info_fetch (match_info, 1); str = g_match_info_fetch (match_info, 1);
g_assert (str); g_assert (str);
local_error = mm_mobile_error_for_code (atoi (str)); local_error = mm_mobile_error_for_code (atoi (str));
g_free (str);
g_match_info_free (match_info);
goto done; goto done;
} }
g_match_info_free (match_info);
/* String CME errors */ /* String CME errors */
found = g_regex_match_full (parser->regex_cme_error_str, 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); str = g_match_info_fetch (match_info, 1);
g_assert (str); g_assert (str);
local_error = mm_mobile_error_for_string (str); local_error = mm_mobile_error_for_string (str);
g_free (str);
g_match_info_free (match_info);
goto done; goto done;
} }
g_match_info_free (match_info);
/* Motorola EZX errors */ /* Motorola EZX errors */
found = g_regex_match_full (parser->regex_ezx_error, 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); str = g_match_info_fetch (match_info, 1);
g_assert (str); g_assert (str);
local_error = mm_mobile_error_for_code (MM_MOBILE_ERROR_UNKNOWN); local_error = mm_mobile_error_for_code (MM_MOBILE_ERROR_UNKNOWN);
g_free (str);
g_match_info_free (match_info);
goto done; goto done;
} }
g_match_info_free (match_info);
/* Last resort; unknown error */ /* Last resort; unknown error */
found = g_regex_match_full (parser->regex_unknown_error, found = g_regex_match_full (parser->regex_unknown_error,
response->str, response->len, response->str, response->len,
0, 0, NULL, NULL); 0, 0, &match_info, NULL);
if (found) { if (found) {
local_error = mm_mobile_error_for_code (MM_MOBILE_ERROR_UNKNOWN); local_error = mm_mobile_error_for_code (MM_MOBILE_ERROR_UNKNOWN);
goto done; goto done;
} }
g_match_info_free (match_info);
/* Connection failures */ /* Connection failures */
found = g_regex_match_full (parser->regex_connect_failed, 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; 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); local_error = mm_modem_connect_error_for_code (code);
} }
done: done:
g_free (str);
g_match_info_free (match_info);
if (found) if (found)
response_clean (response); response_clean (response);