type_decoder.c: Fix a memory leak reported by scan-build.
authorUwe Hermann <uwe@hermann-uwe.de>
Tue, 15 May 2018 22:05:42 +0000 (00:05 +0200)
committerUwe Hermann <uwe@hermann-uwe.de>
Wed, 16 May 2018 09:46:10 +0000 (11:46 +0200)
  type_decoder.c:197:10: warning: Potential leak of memory pointed to by 'pdb'
                 return SRD_ERR_MALLOC;
                        ^~~~~~~~~~~~~~

type_decoder.c

index a61a475f29cfeef981d5cae1f5aacc36938c0117..dfa3fa9e269bb5d5ae984b74290edee775a6dba6 100644 (file)
@@ -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;