From: Uwe Hermann Date: Tue, 15 May 2018 22:05:42 +0000 (+0200) Subject: type_decoder.c: Fix a memory leak reported by scan-build. X-Git-Url: https://sigrok.org/gitweb/?p=libsigrokdecode.git;a=commitdiff_plain;h=48518538aef9dc7ceb2c603319a26ff8750f361e type_decoder.c: Fix a memory leak reported by scan-build. type_decoder.c:197:10: warning: Potential leak of memory pointed to by 'pdb' return SRD_ERR_MALLOC; ^~~~~~~~~~~~~~ --- diff --git a/type_decoder.c b/type_decoder.c index a61a475..dfa3fa9 100644 --- a/type_decoder.c +++ b/type_decoder.c @@ -194,8 +194,10 @@ static int convert_binary(struct srd_decoder_inst *di, PyObject *obj, pdb->bin_class = bin_class; pdb->size = size; - if (!(pdb->data = g_try_malloc(pdb->size))) + if (!(pdb->data = g_try_malloc(pdb->size))) { + g_free(pdb); return SRD_ERR_MALLOC; + } memcpy((void *)pdb->data, (const void *)buf, pdb->size); pdata->data = pdb;