xpcom/tests/TestShutdown.cpp

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rw-r--r--

Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

     1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
     2 /* This Source Code Form is subject to the terms of the Mozilla Public
     3  * License, v. 2.0. If a copy of the MPL was not distributed with this
     4  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     6 #include "nsIServiceManager.h"
     8 // Gee this seems simple! It's for testing for memory leaks with Purify.
    10 void main(int argc, char* argv[])
    11 {
    12     nsresult rv;
    13     nsIServiceManager* servMgr;
    14     rv = NS_InitXPCOM2(&servMgr, nullptr, nullptr);
    15     NS_ASSERTION(NS_SUCCEEDED(rv), "NS_InitXPCOM failed");
    17     // try loading a component and releasing it to see if it leaks
    18     if (argc > 1 && argv[1] != nullptr) {
    19         char* cidStr = argv[1];
    20         nsISupports* obj = nullptr;
    21         if (cidStr[0] == '{') {
    22             nsCID cid;
    23             cid.Parse(cidStr);
    24             rv = CallCreateInstance(cid, &obj);
    25         }
    26         else {
    27             // contractID case:
    28             rv = CallCreateInstance(cidStr, &obj);
    29         }
    30         if (NS_SUCCEEDED(rv)) {
    31             printf("Successfully created %s\n", cidStr);
    32             NS_RELEASE(obj);
    33         }
    34         else {
    35             printf("Failed to create %s (%x)\n", cidStr, rv);
    36         }
    37     }
    39     rv = NS_ShutdownXPCOM(servMgr);
    40     NS_ASSERTION(NS_SUCCEEDED(rv), "NS_ShutdownXPCOM failed");
    41 }

mercurial