From 0357293897ad80eb549e63952551c1781ad41b95 Mon Sep 17 00:00:00 2001 From: Thanasis Antoniou Date: Mon, 16 Dec 2019 22:58:26 +0200 Subject: ANDROID: Fix crash due to adding '.' folder in SearchManager --- backends/fs/posix/posix-fs-factory.cpp | 14 ++++++++++++++ backends/platform/android/asset-archive.cpp | 3 +++ 2 files changed, 17 insertions(+) (limited to 'backends') diff --git a/backends/fs/posix/posix-fs-factory.cpp b/backends/fs/posix/posix-fs-factory.cpp index 94959921f3..e0eebbdbaf 100644 --- a/backends/fs/posix/posix-fs-factory.cpp +++ b/backends/fs/posix/posix-fs-factory.cpp @@ -41,8 +41,22 @@ AbstractFSNode *POSIXFilesystemFactory::makeRootFileNode() const { } AbstractFSNode *POSIXFilesystemFactory::makeCurrentDirectoryFileNode() const { +#if defined(__ANDROID__) + // For Android it does not make sense to have "." in Search Manager as a current directory file node, so we skip it here + // Otherwise this can potentially lead to a crash since, in Android getcwd() returns the root path "/" + // and when SearchMan is used (eg. SearchSet::createReadStreamForMember) and it tries to search root path (and calls POSIXFilesystemNode::getChildren()) + // then a JNI call is made (JNI::getAllStorageLocations()) which leads to a crash if done from the wrong context -- and is also useless overhead as a call in that case. + // This fixes the error case: Loading "Beneath A Steel Sky" with Adlib or FluidSynth audio once, exiting to Launcher via in-game ScummVM menu and re-launching the game. + // Don't return NULL here, since it causes crash with other engines (eg. Blade Runner) + // Returning '.' here will cause POSIXFilesystemNode::getChildren() to ignore it + // + // We also skip adding the '.' directory to SearchManager (in archive.cpp, SearchManager::clear()) + char buf[MAXPATHLEN] = {'.', '\0'}; + return new POSIXFilesystemNode(buf); +#else char buf[MAXPATHLEN]; return getcwd(buf, MAXPATHLEN) ? new POSIXFilesystemNode(buf) : NULL; +#endif } AbstractFSNode *POSIXFilesystemFactory::makeFileNodePath(const Common::String &path) const { diff --git a/backends/platform/android/asset-archive.cpp b/backends/platform/android/asset-archive.cpp index 44e5ed80f2..255262d309 100644 --- a/backends/platform/android/asset-archive.cpp +++ b/backends/platform/android/asset-archive.cpp @@ -71,6 +71,9 @@ AssetInputStream::AssetInputStream(AAssetManager *as, const Common::String &path } AssetInputStream::~AssetInputStream() { + if (_asset != NULL) { + AAsset_close(_asset); + } } void AssetInputStream::close() { -- cgit v1.2.3