hameg-hmo: fix potential NULL dereference
Check for successful allocation before accessing struct members. Return with an error from device initialization when allocation fails. This was reported by clang's scan-build.
This commit is contained in:
parent
addbb09bf8
commit
eac9fcd268
|
@ -664,6 +664,7 @@ SR_PRIV int hmo_init_device(struct sr_dev_inst *sdi)
|
|||
unsigned int i, j, group;
|
||||
struct sr_channel *ch;
|
||||
struct dev_context *devc;
|
||||
int ret;
|
||||
|
||||
devc = sdi->priv;
|
||||
model_index = -1;
|
||||
|
@ -711,12 +712,19 @@ SR_PRIV int hmo_init_device(struct sr_dev_inst *sdi)
|
|||
}
|
||||
|
||||
/* Add digital channel groups. */
|
||||
ret = SR_OK;
|
||||
for (i = 0; i < scope_models[model_index].digital_pods; i++) {
|
||||
devc->digital_groups[i] = g_malloc0(sizeof(struct sr_channel_group));
|
||||
if (!devc->digital_groups[i]) {
|
||||
ret = SR_ERR_MALLOC;
|
||||
break;
|
||||
}
|
||||
devc->digital_groups[i]->name = g_strdup_printf("POD%d", i);
|
||||
sdi->channel_groups = g_slist_append(sdi->channel_groups,
|
||||
devc->digital_groups[i]);
|
||||
}
|
||||
if (ret != SR_OK)
|
||||
return ret;
|
||||
|
||||
/* Add digital channels. */
|
||||
for (i = 0; i < scope_models[model_index].digital_channels; i++) {
|
||||
|
|
Loading…
Reference in New Issue