From: Gerhard Sittig Date: Fri, 9 Feb 2018 17:57:49 +0000 (+0100) Subject: hameg-hmo: fix several compiler warnings (assignments, memory) X-Git-Url: http://sigrok.org/gitweb/?a=commitdiff_plain;h=b0e80e9aa9a7398fa01a7949deb17640ca3c7d47;p=libsigrok.git hameg-hmo: fix several compiler warnings (assignments, memory) Silence warnings about assigned values that never get used, potential NULL deference, and potential memory leaks. This was reported by clang's scan-build. --- diff --git a/src/hardware/hameg-hmo/api.c b/src/hardware/hameg-hmo/api.c index 44841e85..ea2afef6 100644 --- a/src/hardware/hameg-hmo/api.c +++ b/src/hardware/hameg-hmo/api.c @@ -246,8 +246,6 @@ static int config_set(uint32_t key, GVariant *data, state = devc->model_state; update_sample_rate = FALSE; - ret = SR_ERR_NA; - switch (key) { case SR_CONF_LIMIT_FRAMES: devc->frame_limit = g_variant_get_uint64(data); @@ -380,6 +378,8 @@ static int config_list(uint32_t key, GVariant **data, case SR_CONF_COUPLING: if (!cg) return SR_ERR_CHANNEL_GROUP; + if (!model) + return SR_ERR_ARG; *data = g_variant_new_strv(*model->coupling_options, model->num_coupling_options); break; case SR_CONF_TRIGGER_SOURCE: @@ -400,6 +400,8 @@ static int config_list(uint32_t key, GVariant **data, case SR_CONF_VDIV: if (!cg) return SR_ERR_CHANNEL_GROUP; + if (!model) + return SR_ERR_ARG; *data = std_gvar_tuple_array(*model->vdivs, model->num_vdivs); break; default: @@ -552,6 +554,7 @@ static int hmo_setup_channels(const struct sr_dev_inst *sdi) setup_changed = TRUE; break; default: + g_free(pod_enabled); return SR_ERR; } } diff --git a/src/hardware/hameg-hmo/protocol.c b/src/hardware/hameg-hmo/protocol.c index 02fb4d5c..e79901ca 100644 --- a/src/hardware/hameg-hmo/protocol.c +++ b/src/hardware/hameg-hmo/protocol.c @@ -687,9 +687,13 @@ SR_PRIV int hmo_init_device(struct sr_dev_inst *sdi) devc->analog_groups = g_malloc0(sizeof(struct sr_channel_group*) * scope_models[model_index].analog_channels); - devc->digital_groups = g_malloc0(sizeof(struct sr_channel_group*) * scope_models[model_index].digital_pods); + if (!devc->analog_groups || !devc->digital_groups) { + g_free(devc->analog_groups); + g_free(devc->digital_groups); + return SR_ERR_MALLOC; + } /* Add analog channels. */ for (i = 0; i < scope_models[model_index].analog_channels; i++) {