]> git.saurik.com Git - apple/security.git/blobdiff - OSX/libsecurity_utilities/lib/debugging_internal.cpp
Security-59754.80.3.tar.gz
[apple/security.git] / OSX / libsecurity_utilities / lib / debugging_internal.cpp
index d3dcac1777534a9f1d62074d63c3bd3348dd3ad4..c95c802eebd8cd26ca70857c6f6ebf0bcba69120 100644 (file)
@@ -54,7 +54,7 @@ bool dumping(const char *scope)
 #if defined(NDEBUG_STUBS)
     return false;
 #else
-       return Target::get().dump(scope);
+       return Target::get().dumping(scope);
 #endif
 }
 
@@ -218,9 +218,11 @@ void Target::message(const char *scope, const char *format, va_list args)
                // now stuff the message body in, slightly roasted
                size_t left = buffer + sizeof(buffer) - bufp - 1;       // reserve one
                size_t written = vsnprintf(bufp, left, format, args);
-        for (char *p = bufp; *p; p++)
-            if (!isprint(*p))
+        for (char *p = bufp; *p; p++) {
+            if (!isprint(*p)) {
                 *p = '?';
+            }
+        }
                if (written >= left) {  // snprintf overflowed
                        bufp += left;
                        strcpy(bufp - 3, "...");
@@ -255,7 +257,7 @@ void Target::dump(const char *format, va_list args)
        sink->dump(buffer);
 }
 
-bool Target::dump(const char *scope)
+bool Target::dumping(const char *scope)
 {
        return dumpSelector(scope);
 }
@@ -419,6 +421,11 @@ Target &Target::get()
        if (singleton == NULL) {
                Target *t = new Target;
                t->setFromEnvironment();
+
+        // The Target constructor attempts to set singleton to the object. If it didn't succeed, we don't need T anymore.
+        if(singleton != t) {
+            delete t;
+        }
        }
        return *singleton;
 }