Fix linking code after own recent commit.

More stupid mistake in recent enhanced reports for file load code,
rB82c17082ba0e left some read-after-free situations.
This commit is contained in:
2021-06-24 10:53:45 +02:00
parent 3a8347f823
commit 8cdb99d51c
11 changed files with 38 additions and 30 deletions

View File

@@ -87,7 +87,8 @@ bool BKE_copybuffer_read(Main *bmain_dst,
ReportList *reports,
const uint64_t id_types_mask)
{
BlendHandle *bh = BLO_blendhandle_from_file(libname, &(BlendFileReadReport){.reports = reports});
BlendFileReadReport bf_reports = {.reports = reports};
BlendHandle *bh = BLO_blendhandle_from_file(libname, &bf_reports);
if (bh == NULL) {
/* Error reports will have been made by BLO_blendhandle_from_file(). */
return false;
@@ -133,7 +134,8 @@ int BKE_copybuffer_paste(bContext *C,
BlendHandle *bh;
const int id_tag_extra = 0;
bh = BLO_blendhandle_from_file(libname, &(BlendFileReadReport){.reports = reports});
BlendFileReadReport bf_reports = {.reports = reports};
bh = BLO_blendhandle_from_file(libname, &bf_reports);
if (bh == NULL) {
/* error reports will have been made by BLO_blendhandle_from_file() */

View File

@@ -78,10 +78,10 @@ bool BKE_memfile_undo_decode(MemFileUndoData *mfu,
if (UNDO_DISK) {
const struct BlendFileReadParams params = {0};
struct BlendFileData *bfd = BKE_blendfile_read(
mfu->filename, &params, &(BlendFileReadReport){NULL});
BlendFileReadReport bf_reports = {.reports = NULL};
struct BlendFileData *bfd = BKE_blendfile_read(mfu->filename, &params, &bf_reports);
if (bfd != NULL) {
BKE_blendfile_read_setup(C, bfd, &params, &(BlendFileReadReport){NULL});
BKE_blendfile_read_setup(C, bfd, &params, &bf_reports);
success = true;
}
}

View File

@@ -155,7 +155,9 @@ struct BLODataBlockInfo {
};
BlendHandle *BLO_blendhandle_from_file(const char *filepath, struct BlendFileReadReport *reports);
BlendHandle *BLO_blendhandle_from_memory(const void *mem, int memsize);
BlendHandle *BLO_blendhandle_from_memory(const void *mem,
int memsize,
struct BlendFileReadReport *reports);
struct LinkNode *BLO_blendhandle_get_datablock_names(BlendHandle *bh,
int ofblocktype,
@@ -260,6 +262,7 @@ typedef struct TempLibraryContext {
/** Temporary main used to load data into (currently initialized from `real_main`). */
struct Main *bmain_base;
struct BlendHandle *blendhandle;
struct BlendFileReadReport bf_reports;
struct LibraryLink_Params liblink_params;
struct Library *lib;

View File

@@ -83,8 +83,8 @@ bool BLO_main_validate_libraries(Main *bmain, ReportList *reports)
}
BKE_library_filepath_set(bmain, curlib, curlib->filepath);
BlendHandle *bh = BLO_blendhandle_from_file(curlib->filepath_abs,
&(BlendFileReadReport){.reports = reports});
BlendFileReadReport bf_reports = {.reports = reports};
BlendHandle *bh = BLO_blendhandle_from_file(curlib->filepath_abs, &bf_reports);
if (bh == NULL) {
BKE_reportf(reports,

View File

@@ -84,12 +84,13 @@ BlendHandle *BLO_blendhandle_from_file(const char *filepath, BlendFileReadReport
* \param memsize: The size of the data.
* \return A handle on success, or NULL on failure.
*/
BlendHandle *BLO_blendhandle_from_memory(const void *mem, int memsize)
BlendHandle *BLO_blendhandle_from_memory(const void *mem,
int memsize,
BlendFileReadReport *reports)
{
BlendHandle *bh;
bh = (BlendHandle *)blo_filedata_from_memory(
mem, memsize, &(BlendFileReadReport){.reports = NULL});
bh = (BlendHandle *)blo_filedata_from_memory(mem, memsize, reports);
return bh;
}
@@ -398,8 +399,9 @@ BlendFileData *BLO_read_from_memory(const void *mem,
{
BlendFileData *bfd = NULL;
FileData *fd;
BlendFileReadReport bf_reports = {.reports = reports};
fd = blo_filedata_from_memory(mem, memsize, &(BlendFileReadReport){.reports = reports});
fd = blo_filedata_from_memory(mem, memsize, &bf_reports);
if (fd) {
fd->skip_flags = skip_flags;
bfd = blo_read_file_internal(fd, "");
@@ -426,8 +428,9 @@ BlendFileData *BLO_read_from_memfile(Main *oldmain,
BlendFileData *bfd = NULL;
FileData *fd;
ListBase old_mainlist;
BlendFileReadReport bf_reports = {.reports = reports};
fd = blo_filedata_from_memfile(memfile, params, &(BlendFileReadReport){.reports = reports});
fd = blo_filedata_from_memfile(memfile, params, &bf_reports);
if (fd) {
fd->skip_flags = params->skip_flags;
BLI_strncpy(fd->relabase, filename, sizeof(fd->relabase));

View File

@@ -36,12 +36,13 @@ TempLibraryContext *BLO_library_temp_load_id(struct Main *real_main,
{
TempLibraryContext *temp_lib_ctx = MEM_callocN(sizeof(*temp_lib_ctx), __func__);
temp_lib_ctx->bmain_base = BKE_main_new();
temp_lib_ctx->bf_reports.reports = reports;
/* Copy the file path so any path remapping is performed properly. */
STRNCPY(temp_lib_ctx->bmain_base->name, real_main->name);
temp_lib_ctx->blendhandle = BLO_blendhandle_from_file(
blend_file_path, &(BlendFileReadReport){.reports = reports});
temp_lib_ctx->blendhandle = BLO_blendhandle_from_file(blend_file_path,
&temp_lib_ctx->bf_reports);
BLO_library_link_params_init(
&temp_lib_ctx->liblink_params, temp_lib_ctx->bmain_base, 0, LIB_TAG_TEMP_MAIN);

View File

@@ -2894,7 +2894,8 @@ static int filelist_readjob_list_lib(const char *root, ListBase *entries, const
}
/* there we go */
libfiledata = BLO_blendhandle_from_file(dir, &(BlendFileReadReport){.reports = NULL});
BlendFileReadReport bf_reports = {.reports = NULL};
libfiledata = BLO_blendhandle_from_file(dir, &bf_reports);
if (libfiledata == NULL) {
return nbr_entries;
}

View File

@@ -47,8 +47,8 @@ ImBuf *IMB_thumb_load_blend(const char *blen_path, const char *blen_group, const
if (blen_group && blen_id) {
LinkNode *ln, *names, *lp, *previews = NULL;
struct BlendHandle *libfiledata = BLO_blendhandle_from_file(
blen_path, &(BlendFileReadReport){.reports = NULL});
BlendFileReadReport bf_reports = {.reports = NULL};
struct BlendHandle *libfiledata = BLO_blendhandle_from_file(blen_path, &bf_reports);
int idcode = BKE_idtype_idcode_from_name(blen_group);
int i, nprevs, nnames;

View File

@@ -257,9 +257,9 @@ static PyObject *bpy_lib_enter(BPy_Library *self)
ReportList reports;
BKE_reports_init(&reports, RPT_STORE);
BlendFileReadReport bf_reports = {.reports = &reports};
self->blo_handle = BLO_blendhandle_from_file(self->abspath,
&(BlendFileReadReport){.reports = &reports});
self->blo_handle = BLO_blendhandle_from_file(self->abspath, &bf_reports);
if (self->blo_handle == NULL) {
if (BPy_reports_to_error(&reports, PyExc_IOError, true) != -1) {

View File

@@ -1185,16 +1185,12 @@ void wm_homefile_read(bContext *C,
.is_startup = true,
.skip_flags = skip_flags | BLO_READ_SKIP_USERDEF,
};
BlendFileReadReport bf_reports = {.reports = reports};
struct BlendFileData *bfd = BKE_blendfile_read(filepath_startup, &params, &bf_reports);
struct BlendFileData *bfd = BKE_blendfile_read(
filepath_startup, &params, &(BlendFileReadReport){NULL});
if (bfd != NULL) {
BKE_blendfile_read_setup_ex(C,
bfd,
&params,
&(BlendFileReadReport){NULL},
update_defaults && use_data,
app_template);
BKE_blendfile_read_setup_ex(
C, bfd, &params, &bf_reports, update_defaults && use_data, app_template);
success = true;
}
}

View File

@@ -239,12 +239,14 @@ static void wm_link_do(WMLinkAppendData *lapp_data,
for (lib_idx = 0, liblink = lapp_data->libraries.list; liblink;
lib_idx++, liblink = liblink->next) {
char *libname = liblink->link;
BlendFileReadReport bf_reports = {.reports = reports};
if (STREQ(libname, BLO_EMBEDDED_STARTUP_BLEND)) {
bh = BLO_blendhandle_from_memory(datatoc_startup_blend, datatoc_startup_blend_size);
bh = BLO_blendhandle_from_memory(
datatoc_startup_blend, datatoc_startup_blend_size, &bf_reports);
}
else {
bh = BLO_blendhandle_from_file(libname, &(BlendFileReadReport){.reports = reports});
bh = BLO_blendhandle_from_file(libname, &bf_reports);
}
if (bh == NULL) {