From 2a2f3da2fecec6a9bd7cf7e149cd6f2039b4c274 Mon Sep 17 00:00:00 2001 From: Jason Duell Date: Tue, 8 Jan 2013 10:15:02 +0100 Subject: [PATCH] Bug 826846 - B2G: Crash in loop if reinstall existing packaged app. r=jdm --- netwerk/ipc/PRemoteOpenFile.ipdl | 6 ++++-- netwerk/ipc/RemoteOpenFileChild.cpp | 29 ++++++++++++++++++++-------- netwerk/ipc/RemoteOpenFileChild.h | 3 ++- netwerk/ipc/RemoteOpenFileParent.cpp | 5 +++-- 4 files changed, 30 insertions(+), 13 deletions(-) diff --git a/netwerk/ipc/PRemoteOpenFile.ipdl b/netwerk/ipc/PRemoteOpenFile.ipdl index 89d22079d72a..5fc5db4bb662 100644 --- a/netwerk/ipc/PRemoteOpenFile.ipdl +++ b/netwerk/ipc/PRemoteOpenFile.ipdl @@ -26,8 +26,10 @@ parent: __delete__(); child: - // success/failure code, and if NS_SUCCEEDED(rv), an open file descriptor - FileOpened(FileDescriptor fd, nsresult rv); + // Your file handle is ready, Sir... + FileOpened(FileDescriptor fd); + // Trying to send invalid fd crashes, so we need separate method for failure + FileDidNotOpen(); }; diff --git a/netwerk/ipc/RemoteOpenFileChild.cpp b/netwerk/ipc/RemoteOpenFileChild.cpp index ecd9afc3a647..89749abdd695 100644 --- a/netwerk/ipc/RemoteOpenFileChild.cpp +++ b/netwerk/ipc/RemoteOpenFileChild.cpp @@ -138,26 +138,39 @@ RemoteOpenFileChild::AsyncRemoteFileOpen(int32_t aFlags, //----------------------------------------------------------------------------- bool -RemoteOpenFileChild::RecvFileOpened(const FileDescriptor& aFD, - const nsresult& aRV) +RemoteOpenFileChild::RecvFileOpened(const FileDescriptor& aFD) { #if defined(XP_WIN) || defined(MOZ_WIDGET_COCOA) NS_NOTREACHED("osX and Windows shouldn't be doing IPDL here"); #else - if (NS_SUCCEEDED(aRV)) { - mNSPRFileDesc = PR_AllocFileDesc(aFD.PlatformHandle(), PR_GetFileMethods()); - } + mNSPRFileDesc = PR_AllocFileDesc(aFD.PlatformHandle(), PR_GetFileMethods()); MOZ_ASSERT(mListener); - - mListener->OnRemoteFileOpenComplete(aRV); - + mListener->OnRemoteFileOpenComplete(NS_OK); mListener = nullptr; // release ref to listener // This calls NeckoChild::DeallocPRemoteOpenFile(), which deletes |this| if // IPDL holds the last reference. Don't rely on |this| existing after here! Send__delete__(this); +#endif + return true; +} + +bool +RemoteOpenFileChild::RecvFileDidNotOpen() +{ +#if defined(XP_WIN) || defined(MOZ_WIDGET_COCOA) + NS_NOTREACHED("osX and Windows shouldn't be doing IPDL here"); +#else + MOZ_ASSERT(mListener); + printf_stderr("RemoteOpenFileChild: file was not opened!\n"); + mListener->OnRemoteFileOpenComplete(NS_ERROR_FILE_NOT_FOUND); + mListener = nullptr; // release ref to listener + + // This calls NeckoChild::DeallocPRemoteOpenFile(), which deletes |this| if + // IPDL holds the last reference. Don't rely on |this| existing after here! + Send__delete__(this); #endif return true; diff --git a/netwerk/ipc/RemoteOpenFileChild.h b/netwerk/ipc/RemoteOpenFileChild.h index 260718572d91..44877d6d14ff 100644 --- a/netwerk/ipc/RemoteOpenFileChild.h +++ b/netwerk/ipc/RemoteOpenFileChild.h @@ -68,7 +68,8 @@ private: RemoteOpenFileChild(const RemoteOpenFileChild& other); protected: - virtual bool RecvFileOpened(const FileDescriptor&, const nsresult&); + virtual bool RecvFileOpened(const FileDescriptor&); + virtual bool RecvFileDidNotOpen(); // regular nsIFile object, that we forward most calls to. nsCOMPtr mFile; diff --git a/netwerk/ipc/RemoteOpenFileParent.cpp b/netwerk/ipc/RemoteOpenFileParent.cpp index 645b69b462ce..d8492bf30942 100644 --- a/netwerk/ipc/RemoteOpenFileParent.cpp +++ b/netwerk/ipc/RemoteOpenFileParent.cpp @@ -50,7 +50,7 @@ RemoteOpenFileParent::RecvAsyncOpenFile() if (NS_SUCCEEDED(rv)) { int fd = open(path.get(), O_RDONLY); if (fd != -1) { - unused << SendFileOpened(FileDescriptor(fd), NS_OK); + unused << SendFileOpened(FileDescriptor(fd)); // file handle needs to stay open until it's shared with child (and IPDL // is async, so hasn't happened yet). Close in destructor. mFd = fd; @@ -60,7 +60,8 @@ RemoteOpenFileParent::RecvAsyncOpenFile() // Note: sending an invalid file descriptor currently kills the child process: // but that's ok for our use case (failing to open application.jar). - unused << SendFileOpened(FileDescriptor(mFd), NS_ERROR_NOT_AVAILABLE); + printf_stderr("RemoteOpenFileParent: file '%s' was not found!\n", path.get()); + unused << SendFileDidNotOpen(); #endif // OS_TYPE return true;