[PATCH 3/3] core: use g_clear_pointer() to avoid explicitly checking and resetting pointers
Aleksander Morgado
aleksander at aleksander.es
Thu Oct 18 11:19:57 UTC 2018
On 10/18/18 8:06 AM, Ben Chan wrote:
> ---
> src/mm-base-sms.c | 10 ++--------
> src/mm-broadband-modem-mbim.c | 10 ++--------
> 2 files changed, 4 insertions(+), 16 deletions(-)
>
Pushed to git master, thanks.
> diff --git a/src/mm-base-sms.c b/src/mm-base-sms.c
> index e117bef7..25a02617 100644
> --- a/src/mm-base-sms.c
> +++ b/src/mm-base-sms.c
> @@ -939,10 +939,7 @@ sms_store_next_part (GTask *task)
> return;
> }
>
> - if (ctx->msg_data) {
> - g_free (ctx->msg_data);
> - ctx->msg_data = NULL;
> - }
> + g_clear_pointer (&ctx->msg_data, g_free);
>
> if (!sms_get_store_or_send_command ((MMSmsPart *)ctx->current->data,
> ctx->use_pdu_mode,
> @@ -1218,10 +1215,7 @@ sms_send_next_part (GTask *task)
>
> /* Generic send */
>
> - if (ctx->msg_data) {
> - g_free (ctx->msg_data);
> - ctx->msg_data = NULL;
> - }
> + g_clear_pointer (&ctx->msg_data, g_free);
>
> if (!sms_get_store_or_send_command ((MMSmsPart *)ctx->current->data,
> ctx->use_pdu_mode,
> diff --git a/src/mm-broadband-modem-mbim.c b/src/mm-broadband-modem-mbim.c
> index fa5389cf..8f95e60e 100644
> --- a/src/mm-broadband-modem-mbim.c
> +++ b/src/mm-broadband-modem-mbim.c
> @@ -2421,14 +2421,8 @@ update_registration_info (MMBroadbandModemMbim *self,
> self->priv->current_operator_name = operator_name_take;
> }
> } else {
> - if (self->priv->current_operator_id) {
> - g_free (self->priv->current_operator_id);
> - self->priv->current_operator_id = NULL;
> - }
> - if (self->priv->current_operator_name) {
> - g_free (self->priv->current_operator_name);
> - self->priv->current_operator_name = NULL;
> - }
> + g_clear_pointer (&self->priv->current_operator_id, g_free);
> + g_clear_pointer (&self->priv->current_operator_name, g_free);
> g_free (operator_id_take);
> g_free (operator_name_take);
> }
>
--
Aleksander
https://aleksander.es
More information about the ModemManager-devel
mailing list