Skip to content

Commit ac9176a

Browse files
committed
Merge pull request rebol#156 from hostilefork/fix-cc-2068
Free intermediate buffers used by do-codec (CC #2068)
2 parents d68a326 + 7ae3e7a commit ac9176a

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

src/core/n-system.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -450,14 +450,18 @@ REBYTE *evoke_help = "Evoke values:\n"
450450
memcpy(BIN_HEAD(ser), codi.data, codi.len);
451451
Set_Binary(D_RET, ser);
452452
if (result != CODI_BINARY) VAL_SET(D_RET, REB_STRING);
453-
// Free the binary!
453+
454+
// See notice in reb-codec.h on reb_codec_image
455+
Free_Mem(codi.data, codi.len);
454456
break;
455457

456458
case CODI_IMAGE:
457459
ser = Make_Image(codi.w, codi.h, TRUE); // Puts it into RETURN stack position
458460
memcpy(IMG_DATA(ser), codi.bits, codi.w * codi.h * 4);
459461
SET_IMAGE(D_RET, ser);
460-
// Free the image!
462+
463+
// See notice in reb-codec.h on reb_codec_image
464+
Free_Mem(codi.bits, codi.w * codi.h * 4);
461465
break;
462466

463467
case CODI_BLOCK:

src/include/reb-codec.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,17 @@
2929
#define CODI_DEFINED
3030

3131
// Codec image interface:
32+
//
33+
// If your codec routine returns CODI_IMAGE, it is expected that the
34+
// ->bits field contains a block of memory allocated with Make_Mem
35+
// of size (->w * ->h * 4). This will be freed by the
36+
// REBNATIVE(do_codec) in n-system.c
37+
//
38+
// If your codec routine returns CODI_BINARY or CODI_TEXT, it is
39+
// expected that the ->data field contains a block of memory
40+
// allocated with Make_Mem of size ->len. This will be freed by
41+
// the REBNATIVE(do_codec) in n-system.c
42+
//
3243
typedef struct reb_codec_image {
3344
int action;
3445
int w;

0 commit comments

Comments
 (0)