[PATCH] mbimcli: ensure 'cancellable' in Context is always set
Ben Chan
benchan at chromium.org
Wed Jul 26 18:30:13 UTC 2017
As the Context struct is allocated via g_slice_new and its 'cancellable' field
is only set when a GCancellable is provided, there is no guarantee that the
cancellable field is always initialized. This patch fixes the code to always
initialize the cancellable field of the Context struct.
---
We could also address the issue by using g_slice_new0. I don't have a strong
preference here. Considering that there are only two fields to initialize, I
simply opt for allocating Context via g_slice_new and initializing both fields
in Context.
src/mbimcli/mbimcli-atds.c | 3 +--
src/mbimcli/mbimcli-basic-connect.c | 3 +--
src/mbimcli/mbimcli-dss.c | 3 +--
src/mbimcli/mbimcli-ms-firmware-id.c | 3 +--
src/mbimcli/mbimcli-ms-host-shutdown.c | 3 +--
src/mbimcli/mbimcli-phonebook.c | 3 +--
6 files changed, 6 insertions(+), 12 deletions(-)
diff --git a/src/mbimcli/mbimcli-atds.c b/src/mbimcli/mbimcli-atds.c
index c25f71f..b991120 100644
--- a/src/mbimcli/mbimcli-atds.c
+++ b/src/mbimcli/mbimcli-atds.c
@@ -297,8 +297,7 @@ mbimcli_atds_run (MbimDevice *device,
/* Initialize context */
ctx = g_slice_new (Context);
ctx->device = g_object_ref (device);
- if (cancellable)
- ctx->cancellable = g_object_ref (cancellable);
+ ctx->cancellable = cancellable ? g_object_ref (cancellable) : NULL;
/* Request to get signal info? */
if (query_signal_flag) {
diff --git a/src/mbimcli/mbimcli-basic-connect.c b/src/mbimcli/mbimcli-basic-connect.c
index cae1f99..204ecb9 100644
--- a/src/mbimcli/mbimcli-basic-connect.c
+++ b/src/mbimcli/mbimcli-basic-connect.c
@@ -1548,8 +1548,7 @@ mbimcli_basic_connect_run (MbimDevice *device,
/* Initialize context */
ctx = g_slice_new (Context);
ctx->device = g_object_ref (device);
- if (cancellable)
- ctx->cancellable = g_object_ref (cancellable);
+ ctx->cancellable = cancellable ? g_object_ref (cancellable) : NULL;
/* Request to get capabilities? */
if (query_device_caps_flag) {
diff --git a/src/mbimcli/mbimcli-dss.c b/src/mbimcli/mbimcli-dss.c
index 76866b9..1e26130 100644
--- a/src/mbimcli/mbimcli-dss.c
+++ b/src/mbimcli/mbimcli-dss.c
@@ -259,8 +259,7 @@ mbimcli_dss_run (MbimDevice *device,
/* Initialize context */
ctx = g_slice_new (Context);
ctx->device = g_object_ref (device);
- if (cancellable)
- ctx->cancellable = g_object_ref (cancellable);
+ ctx->cancellable = cancellable ? g_object_ref (cancellable) : NULL;
/* Connect? */
if (connect_str) {
diff --git a/src/mbimcli/mbimcli-ms-firmware-id.c b/src/mbimcli/mbimcli-ms-firmware-id.c
index 9cbd255..69d662e 100644
--- a/src/mbimcli/mbimcli-ms-firmware-id.c
+++ b/src/mbimcli/mbimcli-ms-firmware-id.c
@@ -153,8 +153,7 @@ mbimcli_ms_firmware_id_run (MbimDevice *device,
/* Initialize context */
ctx = g_slice_new (Context);
ctx->device = g_object_ref (device);
- if (cancellable)
- ctx->cancellable = g_object_ref (cancellable);
+ ctx->cancellable = cancellable ? g_object_ref (cancellable) : NULL;
/* Request to get firmware ID? */
if (query_firmware_id_flag) {
diff --git a/src/mbimcli/mbimcli-ms-host-shutdown.c b/src/mbimcli/mbimcli-ms-host-shutdown.c
index 3fa7869..ee6361a 100644
--- a/src/mbimcli/mbimcli-ms-host-shutdown.c
+++ b/src/mbimcli/mbimcli-ms-host-shutdown.c
@@ -137,8 +137,7 @@ mbimcli_ms_host_shutdown_run (MbimDevice *device,
/* Initialize context */
ctx = g_slice_new (Context);
ctx->device = g_object_ref (device);
- if (cancellable)
- ctx->cancellable = g_object_ref (cancellable);
+ ctx->cancellable = cancellable ? g_object_ref (cancellable) : NULL;
/* Request to notify that host is shutting down */
if (notify_host_shutdown_flag) {
diff --git a/src/mbimcli/mbimcli-phonebook.c b/src/mbimcli/mbimcli-phonebook.c
index bb4e1c0..2fa46a6 100644
--- a/src/mbimcli/mbimcli-phonebook.c
+++ b/src/mbimcli/mbimcli-phonebook.c
@@ -353,8 +353,7 @@ mbimcli_phonebook_run (MbimDevice *device,
/* Initialize context */
ctx = g_slice_new (Context);
ctx->device = g_object_ref (device);
- if (cancellable)
- ctx->cancellable = g_object_ref (cancellable);
+ ctx->cancellable = cancellable ? g_object_ref (cancellable) : NULL;
/* Request to get configuration? */
if (phonebook_configuration_flag) {
--
2.14.0.rc0.400.g1c36432dff-goog
More information about the libmbim-devel
mailing list