bearer-qmi: plug memleaks when connection attempt fails early

The data and qmi objects were not being correctly disposed on several
error conditions.
This commit is contained in:
Aleksander Morgado
2019-11-25 09:48:05 +01:00
parent 260d34be76
commit c523d5bdc3

View File

@@ -1518,8 +1518,8 @@ _connect (MMBaseBearer *self,
MMBearerProperties *properties = NULL; MMBearerProperties *properties = NULL;
ConnectContext *ctx; ConnectContext *ctx;
MMBaseModem *modem = NULL; MMBaseModem *modem = NULL;
MMPort *data; MMPort *data = NULL;
MMPortQmi *qmi; MMPortQmi *qmi = NULL;
GError *error = NULL; GError *error = NULL;
const gchar *apn; const gchar *apn;
GTask *task; GTask *task;
@@ -1540,8 +1540,7 @@ _connect (MMBaseBearer *self,
MM_CORE_ERROR, MM_CORE_ERROR,
MM_CORE_ERROR_NOT_FOUND, MM_CORE_ERROR_NOT_FOUND,
"No valid data port found to launch connection"); "No valid data port found to launch connection");
g_object_unref (modem); goto out;
return;
} }
/* Each data port has a single QMI port associated */ /* Each data port has a single QMI port associated */
@@ -1553,9 +1552,7 @@ _connect (MMBaseBearer *self,
user_data, user_data,
_connect, _connect,
error); error);
g_object_unref (data); goto out;
g_object_unref (modem);
return;
} }
/* Check whether we have an APN */ /* Check whether we have an APN */
@@ -1571,8 +1568,7 @@ _connect (MMBaseBearer *self,
MM_CORE_ERROR, MM_CORE_ERROR,
MM_CORE_ERROR_INVALID_ARGS, MM_CORE_ERROR_INVALID_ARGS,
"3GPP connection logic requires APN setting"); "3GPP connection logic requires APN setting");
g_object_unref (modem); goto out;
return;
} }
/* Is this a 3GPP2 only modem and APN was given? If so, error */ /* Is this a 3GPP2 only modem and APN was given? If so, error */
@@ -1585,12 +1581,9 @@ _connect (MMBaseBearer *self,
MM_CORE_ERROR, MM_CORE_ERROR,
MM_CORE_ERROR_INVALID_ARGS, MM_CORE_ERROR_INVALID_ARGS,
"3GPP2 doesn't support APN setting"); "3GPP2 doesn't support APN setting");
g_object_unref (modem); goto out;
return;
} }
g_object_unref (modem);
mm_dbg ("Launching connection with QMI port (%s/%s) and data port (%s/%s)", mm_dbg ("Launching connection with QMI port (%s/%s) and data port (%s/%s)",
mm_port_subsys_get_string (mm_port_get_subsys (MM_PORT (qmi))), mm_port_subsys_get_string (mm_port_get_subsys (MM_PORT (qmi))),
mm_port_get_device (MM_PORT (qmi)), mm_port_get_device (MM_PORT (qmi)),
@@ -1599,8 +1592,8 @@ _connect (MMBaseBearer *self,
ctx = g_slice_new0 (ConnectContext); ctx = g_slice_new0 (ConnectContext);
ctx->self = g_object_ref (self); ctx->self = g_object_ref (self);
ctx->qmi = qmi; ctx->qmi = g_object_ref (qmi);
ctx->data = data; ctx->data = g_object_ref (data);
ctx->step = CONNECT_STEP_FIRST; ctx->step = CONNECT_STEP_FIRST;
ctx->ip_method = MM_BEARER_IP_METHOD_UNKNOWN; ctx->ip_method = MM_BEARER_IP_METHOD_UNKNOWN;
@@ -1653,7 +1646,7 @@ _connect (MMBaseBearer *self,
str); str);
g_object_unref (task); g_object_unref (task);
g_free (str); g_free (str);
return; goto out;
} }
auth = mm_bearer_properties_get_allowed_auth (properties); auth = mm_bearer_properties_get_allowed_auth (properties);
@@ -1679,12 +1672,17 @@ _connect (MMBaseBearer *self,
str); str);
g_object_unref (task); g_object_unref (task);
g_free (str); g_free (str);
return; goto out;
} }
} }
/* Run! */ /* Run! */
connect_context_step (task); connect_context_step (task);
out:
g_clear_object (&qmi);
g_clear_object (&data);
g_clear_object (&modem);
} }
/*****************************************************************************/ /*****************************************************************************/