Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBastien Montagne <montagne29@wanadoo.fr>2015-02-04 16:46:22 +0300
committerBastien Montagne <montagne29@wanadoo.fr>2015-02-04 17:40:28 +0300
commit292444e3f5c2c1df45a949cca0a0be430a5ba57c (patch)
treec1a25fa7651cf8b863b59d87ef042ce0567635f1 /source/blender
parentfe03bc2a02a0c9e5ecd554f72839ae0a407a8e86 (diff)
RNA image.pack(): fix possible memleak, add possibility to pass raw bytes data.
Note passing data assumes user knows what he is doing, else segfault is guaranted (there is no good ways to pass raw bytes data to RNA func currently, and using int array is way too heavy in this case). And image->packedfile was never freed...
Diffstat (limited to 'source/blender')
-rw-r--r--source/blender/makesrna/intern/rna_image_api.c15
1 files changed, 14 insertions, 1 deletions
diff --git a/source/blender/makesrna/intern/rna_image_api.c b/source/blender/makesrna/intern/rna_image_api.c
index 90f90ea8632..63bd50e7ada 100644
--- a/source/blender/makesrna/intern/rna_image_api.c
+++ b/source/blender/makesrna/intern/rna_image_api.c
@@ -144,7 +144,7 @@ static void rna_Image_save(Image *image, bContext *C, ReportList *reports)
WM_event_add_notifier(C, NC_IMAGE | NA_EDITED, image);
}
-static void rna_Image_pack(Image *image, bContext *C, ReportList *reports, int as_png)
+static void rna_Image_pack(Image *image, bContext *C, ReportList *reports, int as_png, const char *data, int data_len)
{
ImBuf *ibuf = BKE_image_acquire_ibuf(image, NULL, NULL);
@@ -152,9 +152,18 @@ static void rna_Image_pack(Image *image, bContext *C, ReportList *reports, int a
BKE_report(reports, RPT_ERROR, "Cannot pack edited image from disk, only as internal PNG");
}
else {
+ if (image->packedfile) {
+ freePackedFile(image->packedfile);
+ image->packedfile = NULL;
+ }
if (as_png) {
BKE_image_memorypack(image);
}
+ else if (data) {
+ char *data_dup = MEM_mallocN(sizeof(*data_dup) * (size_t)data_len, __func__);
+ memcpy(data_dup, data, (size_t)data_len);
+ image->packedfile = newPackedFileMemory(data_dup, data_len);
+ }
else {
image->packedfile = newPackedFile(reports, image->name, ID_BLEND_PATH(G.main, &image->id));
}
@@ -307,6 +316,10 @@ void RNA_api_image(StructRNA *srna)
RNA_def_function_ui_description(func, "Pack an image as embedded data into the .blend file");
RNA_def_function_flag(func, FUNC_USE_CONTEXT | FUNC_USE_REPORTS);
RNA_def_boolean(func, "as_png", 0, "as_png", "Pack the image as PNG (needed for generated/dirty images)");
+ parm = RNA_def_property(func, "data", PROP_STRING, PROP_BYTESTRING);
+ RNA_def_property_ui_text(parm, "data", "Raw data (bytes, exact content of the embedded file)");
+ RNA_def_int(func, "data_len", 0, 0, INT_MAX,
+ "data_len", "length of given data (mandatory if data is provided)", 0, INT_MAX);
func = RNA_def_function(srna, "unpack", "rna_Image_unpack");
RNA_def_function_ui_description(func, "Save an image packed in the .blend file to disk");