]> sigrok.org Git - libsigrok.git/commitdiff
hameg-hmo: fix several compiler warnings (assignments, memory)
authorGerhard Sittig <redacted>
Fri, 9 Feb 2018 17:57:49 +0000 (18:57 +0100)
committerUwe Hermann <redacted>
Fri, 9 Feb 2018 20:37:39 +0000 (21:37 +0100)
Silence warnings about assigned values that never get used, potential
NULL deference, and potential memory leaks.

This was reported by clang's scan-build.

src/hardware/hameg-hmo/api.c
src/hardware/hameg-hmo/protocol.c

index 44841e852c18d5d705a60d020637b09ce89bdda5..ea2afef621867ed774703497f7588e961ee6b48e 100644 (file)
@@ -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;
                }
        }
index 02fb4d5c8846154e4742aa7c3474f7589b08bdd5..e79901caaf37ee447f53119ae87d759005b14543 100644 (file)
@@ -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++) {