HTTPMediaIO: fix crash on exit.

- Remove custom BUrlContext, use the shared one to simplify ownership
  management. This means all HTTP media streams in an application share
  the same context (including cookies), however.
- Fix deletion of the BUrlRequest object, which cannot reliably happen
  before the thread has exited. RequestCompleted is too early.
This commit is contained in:
Adrien Destugues
2016-10-31 18:12:20 +01:00
parent 05574d9b2f
commit 98e33bf69a
2 changed files with 2 additions and 11 deletions
@@ -85,7 +85,6 @@ public:
return; return;
fRequest = NULL; fRequest = NULL;
delete request;
} }
status_t LockOnInit(bigtime_t timeout) status_t LockOnInit(bigtime_t timeout)
@@ -119,7 +118,6 @@ private:
HTTPMediaIO::HTTPMediaIO(BUrl url) HTTPMediaIO::HTTPMediaIO(BUrl url)
: :
BAdapterIO(B_MEDIA_STREAMING | B_MEDIA_SEEKABLE, HTTP_TIMEOUT), BAdapterIO(B_MEDIA_STREAMING | B_MEDIA_SEEKABLE, HTTP_TIMEOUT),
fContext(NULL),
fReq(NULL), fReq(NULL),
fListener(NULL), fListener(NULL),
fReqThread(-1), fReqThread(-1),
@@ -127,10 +125,6 @@ HTTPMediaIO::HTTPMediaIO(BUrl url)
fIsMutable(false) fIsMutable(false)
{ {
CALLED(); CALLED();
// The context has the same life time of the object
fContext = new BUrlContext();
fContext->AcquireReference();
} }
@@ -142,8 +136,7 @@ HTTPMediaIO::~HTTPMediaIO()
status_t status; status_t status;
wait_for_thread(fReqThread, &status); wait_for_thread(fReqThread, &status);
fContext->ReleaseReference(); delete fReq;
delete fContext;
} }
@@ -177,8 +170,7 @@ HTTPMediaIO::Open()
fListener = new FileListener(this); fListener = new FileListener(this);
fReq = BUrlProtocolRoster::MakeRequest(fUrl, fReq = BUrlProtocolRoster::MakeRequest(fUrl, fListener);
fListener, fContext);
if (fReq == NULL) if (fReq == NULL)
return B_ERROR; return B_ERROR;
@@ -40,7 +40,6 @@ protected:
friend class FileListener; friend class FileListener;
private: private:
BUrlContext* fContext;
BUrlRequest* fReq; BUrlRequest* fReq;
FileListener* fListener; FileListener* fListener;
thread_id fReqThread; thread_id fReqThread;