Check pointers' validity before dereferencing them. Release partially
allocated memory in an error path. Remove an assignment which never took
effect.
This was reported by clang's scan-build.
{
const struct scope_config *model;
+ if (!devc)
+ return CG_INVALID;
model = devc->model_config;
if (!cg)
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);
*data = g_variant_new_strv(ARRAY_AND_SIZE(dlm_trigger_slopes));
return SR_OK;
case SR_CONF_NUM_HDIV:
+ if (!model)
+ return SR_ERR_ARG;
*data = g_variant_new_uint32(model->num_xdivs);
return SR_OK;
default:
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].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, each in its own group. */
for (i = 0; i < scope_models[model_index].analog_channels; i++) {