diff options
author | Sybren A. Stüvel <sybren@blender.org> | 2021-07-15 16:44:33 +0300 |
---|---|---|
committer | Sybren A. Stüvel <sybren@blender.org> | 2021-07-15 17:04:22 +0300 |
commit | 60fee69682ac399204404a03ba99845787a53e39 (patch) | |
tree | eb4dcf0e5cbe9bd1a97166829645ec695d5e8708 /source/blender | |
parent | 3df40cc343f09926c044dd9eeb7f81f5360ff330 (diff) |
Library loading: Fix access of out-of-scope memory in py context manager
The `__enter__` function of the `bpy.data.libraries.load` context manager
was storing a pointer to a stack-allocated variable, which was subsequently
used in the `__exit__` function, causing a crash. This is now fixed.
Thanks @Severin for the patch.
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/python/intern/bpy_library_load.c | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/source/blender/python/intern/bpy_library_load.c b/source/blender/python/intern/bpy_library_load.c index 28a97c3fa3b..d9a357c5e2e 100644 --- a/source/blender/python/intern/bpy_library_load.c +++ b/source/blender/python/intern/bpy_library_load.c @@ -66,6 +66,8 @@ typedef struct { char relpath[FILE_MAX]; char abspath[FILE_MAX]; /* absolute path */ BlendHandle *blo_handle; + /* Referenced by `blo_handle`, so stored here to keep alive for long enough. */ + BlendFileReadReport bf_reports; int flag; PyObject *dict; /* Borrowed reference to the `bmain`, taken from the RNA instance of #RNA_BlendDataLibraries. @@ -259,7 +261,8 @@ static PyObject *bpy_lib_enter(BPy_Library *self) BKE_reports_init(&reports, RPT_STORE); BlendFileReadReport bf_reports = {.reports = &reports}; - self->blo_handle = BLO_blendhandle_from_file(self->abspath, &bf_reports); + self->bf_reports = bf_reports; + self->blo_handle = BLO_blendhandle_from_file(self->abspath, &self->bf_reports); if (self->blo_handle == NULL) { if (BPy_reports_to_error(&reports, PyExc_IOError, true) != -1) { |