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") {