diff options
author | Sergey Sharybin <sergey.vfx@gmail.com> | 2017-05-16 16:34:43 +0300 |
---|---|---|
committer | Sergey Sharybin <sergey.vfx@gmail.com> | 2017-05-16 16:36:29 +0300 |
commit | 26b232318930739a73d88afc9aaca7992301f03a (patch) | |
tree | 7850d9aba71773670b19a25fd277ef61e1cedb9d /source | |
parent | 8be9d68dd42d6831675356bfa0e1bf9274680df3 (diff) |
Fix memory leak when saving OpenEXR files
It is not a good idea to:
1. Duplicate metadata to self
2. Ignore the fact that something might have had metadata already.
Also moved metadata copy to a preparation function, so it is
never lost.
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/editors/space_image/image_ops.c | 1 | ||||
-rw-r--r-- | source/blender/imbuf/intern/colormanagement.c | 4 | ||||
-rw-r--r-- | source/blender/imbuf/intern/metadata.c | 2 |
3 files changed, 6 insertions, 1 deletions
diff --git a/source/blender/editors/space_image/image_ops.c b/source/blender/editors/space_image/image_ops.c index d00ebed5bcc..c2cfca295a4 100644 --- a/source/blender/editors/space_image/image_ops.c +++ b/source/blender/editors/space_image/image_ops.c @@ -1890,7 +1890,6 @@ static bool save_image_doit(bContext *C, SpaceImage *sima, wmOperator *op, SaveI } else { colormanaged_ibuf = IMB_colormanagement_imbuf_for_write(ibuf, save_as_render, true, &imf->view_settings, &imf->display_settings, imf); - IMB_metadata_copy(colormanaged_ibuf, ibuf); ok = BKE_imbuf_write_as(colormanaged_ibuf, simopts->filepath, imf, save_copy); save_imbuf_post(ibuf, colormanaged_ibuf); } diff --git a/source/blender/imbuf/intern/colormanagement.c b/source/blender/imbuf/intern/colormanagement.c index cdb8f2c6fa2..a4d5da9993a 100644 --- a/source/blender/imbuf/intern/colormanagement.c +++ b/source/blender/imbuf/intern/colormanagement.c @@ -2065,6 +2065,10 @@ ImBuf *IMB_colormanagement_imbuf_for_write(ImBuf *ibuf, bool save_as_render, boo } } + if (colormanaged_ibuf != ibuf) { + IMB_metadata_copy(colormanaged_ibuf, ibuf); + } + return colormanaged_ibuf; } diff --git a/source/blender/imbuf/intern/metadata.c b/source/blender/imbuf/intern/metadata.c index 134bbe88f15..d48aec0ba4c 100644 --- a/source/blender/imbuf/intern/metadata.c +++ b/source/blender/imbuf/intern/metadata.c @@ -81,7 +81,9 @@ bool IMB_metadata_get_field(struct ImBuf *img, const char *key, char *field, con void IMB_metadata_copy(struct ImBuf *dimb, struct ImBuf *simb) { + BLI_assert(dimb != simb); if (simb->metadata) { + IDP_FreeProperty(dimb->metadata); dimb->metadata = IDP_CopyProperty(simb->metadata); } } |