Potential memory leak if DmtxEncode is re-used
sled opened this issue · 0 comments
sled commented
I think dmtxEncodeDataMatrix
should free the image->pxl
buffer if the DmtxEncode
struct is re-used, e.g.:
unsigned char str[] = "30Q324343430794<OQQ";
DmtxEncode *enc;
enc = dmtxEncodeCreate();
dmtxEncodeDataMatrix(enc, strlen(str), str);
dmtxEncodeDataMatrix(enc, strlen(str), str);
dmtxEncodeDestroy(&enc);
Here the image
from the first call gets overwritten: https://github.com/dmtx/libdmtx/blob/master/dmtxencode.c#L222
The call to dmtxEncodeDestroy
only deletes the second pixel buffer in my example above, see: https://github.com/dmtx/libdmtx/blob/master/dmtxencode.c#L70
I'd suggest to call dmtxImageDestroy
and free
ing the pixel buffer in the dmtxEncodeDataMatrix
function if an image
is present from a previous call.