From 807bd20a8f13854c2c198aba25a6f4036726832e Mon Sep 17 00:00:00 2001 From: Adrien Destugues Date: Tue, 22 Jul 2014 17:21:57 +0200 Subject: [PATCH] Allocate the default UrlContext as a BReferenceable BUrlContext now inherits BReferenceable to make it easier to handle the context lifespan. Make the default context an always-retained reference to match this. No functional change in normal conditions, however this avoids an assert when BReferenceable is built in debug mode. --- src/kits/network/libnetapi/UrlProtocolRoster.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/kits/network/libnetapi/UrlProtocolRoster.cpp b/src/kits/network/libnetapi/UrlProtocolRoster.cpp index 17018bf362..4b44c9999f 100644 --- a/src/kits/network/libnetapi/UrlProtocolRoster.cpp +++ b/src/kits/network/libnetapi/UrlProtocolRoster.cpp @@ -18,7 +18,7 @@ #include -static BUrlContext gDefaultContext; +static BReference gDefaultContext = new(std::nothrow) BUrlContext(); /* static */ BUrlRequest* @@ -26,7 +26,13 @@ BUrlProtocolRoster::MakeRequest(const BUrl& url, BUrlProtocolListener* listener, BUrlContext* context) { if (context == NULL) - context = &gDefaultContext; + context = gDefaultContext; + + if (context == NULL) { + // Allocation of the gDefaultContext failed. Don't allow creating + // requests without a context. + return NULL; + } // TODO: instanciate the correct BUrlProtocol using add-on interface if (url.Protocol() == "http") {