Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions dmtxencode.c
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,10 @@ dmtxEncodeGetProp(DmtxEncode *enc, int prop)
enc->region.mappingRows = dmtxGetSymbolAttribute(DmtxSymAttribMappingMatrixRows, sizeIdx);
enc->region.mappingCols = dmtxGetSymbolAttribute(DmtxSymAttribMappingMatrixCols, sizeIdx);

/* Free any message left over from a previous call on this DmtxEncode
before allocating a new one, to avoid leaking it (see issue #40) */
dmtxMessageDestroy(&(enc->message));

/* Allocate memory for message and array */
enc->message = dmtxMessageCreate(sizeIdx, DmtxFormatMatrix);
enc->message->padCount = 0; /* XXX this needs to be added back */
Expand All @@ -233,6 +237,14 @@ dmtxEncodeGetProp(DmtxEncode *enc, int prop)
return DmtxFail;
}

/* Free any image left over from a previous call on this DmtxEncode
before allocating a new one, to avoid leaking it (see issue #40) */
if(enc->image != NULL && enc->image->pxl != NULL) {
free(enc->image->pxl);
enc->image->pxl = NULL;
}
dmtxImageDestroy(&(enc->image));

enc->image = dmtxImageCreate(pxl, width, height, enc->pixelPacking);
if(enc->image == NULL) {
perror("image malloc error");
Expand Down