]> sigrok.org Git - libsigrokdecode.git/blobdiff - type_decoder.c
instance.c: Fix a memory leak reported by scan-build.
[libsigrokdecode.git] / type_decoder.c
index a61a475f29cfeef981d5cae1f5aacc36938c0117..35187a598a2d6ca19c5f09441f02955340e2468b 100644 (file)
@@ -186,16 +186,18 @@ static int convert_binary(struct srd_decoder_inst *di, PyObject *obj,
                goto err;
        }
 
-       pdb = g_malloc(sizeof(struct srd_proto_data_binary));
        if (PyBytes_AsStringAndSize(py_tmp, &buf, &size) == -1)
                goto err;
 
        PyGILState_Release(gstate);
 
+       pdb = g_malloc(sizeof(struct srd_proto_data_binary));
        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;