Index: src/amiga-library.m ================================================================== --- src/amiga-library.m +++ src/amiga-library.m @@ -294,12 +294,13 @@ return &child->library; } static void * -expunge(struct ObjFWBase *base) +expunge(struct ObjFWBase *base, struct ExecBase *sysBase) { +#define SysBase sysBase void *segList; if (base->parent != NULL) { base->parent->library.lib_Flags |= LIBF_DELEXP; return 0; @@ -315,23 +316,31 @@ Remove(&base->library.lib_Node); FreeMem((char *)base - base->library.lib_NegSize, base->library.lib_NegSize + base->library.lib_PosSize); return segList; +#undef SysBase } static void *__saveds lib_expunge(void) { OF_M68K_ARG(struct ObjFWBase *, base, a6) - return expunge(base); + return expunge(base, SysBase); } static void *__saveds lib_close(void) { + /* + * SysBase becomes invalid during this function, so we store it in + * sysBase and add a define to make the inlines use the right one. + */ + struct ExecBase *sysBase = SysBase; +#define SysBase sysBase + OF_M68K_ARG(struct ObjFWBase *, base, a6) if (base->parent != NULL) { struct ObjFWBase *parent; @@ -351,13 +360,14 @@ base = parent; } if (--base->library.lib_OpenCnt == 0 && (base->library.lib_Flags & LIBF_DELEXP)) - return expunge(base); + return expunge(base, sysBase); return NULL; +#undef SysBase } static void * lib_null(void) {