Skip to content

Commit

Permalink
Merge pull request rebol#156 from hostilefork/fix-cc-2068
Browse files Browse the repository at this point in the history
Free intermediate buffers used by do-codec (CC #2068)
  • Loading branch information
carls committed Feb 15, 2014
2 parents d68a326 + 7ae3e7a commit ac9176a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/core/n-system.c
Original file line number Diff line number Diff line change
Expand Up @@ -450,14 +450,18 @@ REBYTE *evoke_help = "Evoke values:\n"
memcpy(BIN_HEAD(ser), codi.data, codi.len);
Set_Binary(D_RET, ser);
if (result != CODI_BINARY) VAL_SET(D_RET, REB_STRING);
// Free the binary!

// See notice in reb-codec.h on reb_codec_image
Free_Mem(codi.data, codi.len);
break;

case CODI_IMAGE:
ser = Make_Image(codi.w, codi.h, TRUE); // Puts it into RETURN stack position
memcpy(IMG_DATA(ser), codi.bits, codi.w * codi.h * 4);
SET_IMAGE(D_RET, ser);
// Free the image!

// See notice in reb-codec.h on reb_codec_image
Free_Mem(codi.bits, codi.w * codi.h * 4);
break;

case CODI_BLOCK:
Expand Down
11 changes: 11 additions & 0 deletions src/include/reb-codec.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,17 @@
#define CODI_DEFINED

// Codec image interface:
//
// If your codec routine returns CODI_IMAGE, it is expected that the
// ->bits field contains a block of memory allocated with Make_Mem
// of size (->w * ->h * 4). This will be freed by the
// REBNATIVE(do_codec) in n-system.c
//
// If your codec routine returns CODI_BINARY or CODI_TEXT, it is
// expected that the ->data field contains a block of memory
// allocated with Make_Mem of size ->len. This will be freed by
// the REBNATIVE(do_codec) in n-system.c
//
typedef struct reb_codec_image {
int action;
int w;
Expand Down

0 comments on commit ac9176a

Please sign in to comment.