From: Gerhard Sittig Date: Sat, 10 Feb 2018 11:20:05 +0000 (+0100) Subject: hameg-hmo: fix potential NULL dereference X-Git-Url: https://sigrok.org/gitweb/?a=commitdiff_plain;h=eac9fcd2685a0068a9c9884a2b96629088a20ca5;hp=addbb09bf81444030dcd17094e8892a91875b157;p=libsigrok.git 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. --- diff --git a/src/hardware/hameg-hmo/protocol.c b/src/hardware/hameg-hmo/protocol.c index e79901ca..059ae439 100644 --- a/src/hardware/hameg-hmo/protocol.c +++ b/src/hardware/hameg-hmo/protocol.c @@ -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++) {