[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[or-cvs] [tor/release-0.2.2] Only add each log message to pending_cb_messages once.



commit cc051f9aca96b55533953cfcc10c86f9fe1e7b9a
Author: Robert Ransom <rransom.8774@xxxxxxxxx>
Date:   Sat Dec 11 05:26:36 2010 -0800

    Only add each log message to pending_cb_messages once.
---
 src/common/log.c |   15 ++++++++++-----
 1 files changed, 10 insertions(+), 5 deletions(-)

diff --git a/src/common/log.c b/src/common/log.c
index f63c3fb..1324ff0 100644
--- a/src/common/log.c
+++ b/src/common/log.c
@@ -272,6 +272,7 @@ logv(int severity, log_domain_mask_t domain, const char *funcname,
   int formatted = 0;
   logfile_t *lf;
   char *end_of_prefix=NULL;
+  int callbacks_deferred = 0;
 
   /* Call assert, not tor_assert, since tor_assert calls log on failure. */
   assert(format);
@@ -328,11 +329,15 @@ logv(int severity, log_domain_mask_t domain, const char *funcname,
       continue;
     } else if (lf->callback) {
       if (domain & LD_NOCB) {
-        pending_cb_message_t *msg = tor_malloc(sizeof(pending_cb_message_t));
-        msg->severity = severity;
-        msg->domain = domain;
-        msg->msg = tor_strdup(end_of_prefix);
-        smartlist_add(pending_cb_messages, msg);
+        if (!callbacks_deferred) {
+          pending_cb_message_t *msg = tor_malloc(sizeof(pending_cb_message_t));
+          msg->severity = severity;
+          msg->domain = domain;
+          msg->msg = tor_strdup(end_of_prefix);
+          smartlist_add(pending_cb_messages, msg);
+
+          callbacks_deferred = 1;
+        }
       } else {
         lf->callback(severity, domain, end_of_prefix);
       }