From: Uwe Hermann Date: Fri, 25 Sep 2015 07:00:05 +0000 (+0200) Subject: manson-hcs-3xxx: Fix use-after-free and memory leaks. X-Git-Tag: libsigrok-0.4.0~250 X-Git-Url: http://sigrok.org/gitweb/?a=commitdiff_plain;h=6e799d0799abb2c8c0ca75238fff902e31453108;p=libsigrok.git manson-hcs-3xxx: Fix use-after-free and memory leaks. Thanks to Hannu Vuolasaho for the report! --- diff --git a/src/hardware/manson-hcs-3xxx/api.c b/src/hardware/manson-hcs-3xxx/api.c index 0662a81e..e79e59dc 100644 --- a/src/hardware/manson-hcs-3xxx/api.c +++ b/src/hardware/manson-hcs-3xxx/api.c @@ -145,12 +145,12 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options) if (!strcmp(models[i].id, tokens[0])) model_id = i; } - g_strfreev(tokens); - if (model_id < 0) { - sr_err("Unknown model id '%s' detected, aborting.", tokens[0]); + sr_err("Unknown model ID '%s' detected, aborting.", tokens[0]); + g_strfreev(tokens); return NULL; } + g_strfreev(tokens); /* Init device instance, etc. */ sdi = g_malloc0(sizeof(struct sr_dev_inst)); @@ -173,8 +173,10 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options) (hcs_read_reply(serial, 2, reply, sizeof(reply)) < 0)) goto exit_err; tokens = g_strsplit((const gchar *)&reply, "\r", 2); - if (hcs_parse_volt_curr_mode(sdi, tokens) < 0) + if (hcs_parse_volt_curr_mode(sdi, tokens) < 0) { + g_strfreev(tokens); goto exit_err; + } g_strfreev(tokens); /* Get max. voltage and current. */