All pastes #161165 Raw Edit

Untitled

public text v1 · immutable
·published 2006-09-05 02:16 UTC
rendered paste body
Index: main/logger.c
===================================================================
--- main/logger.c       (revision 42010)
+++ main/logger.c       (working copy)
@@ -124,8 +124,8 @@
        const char *file;
        int line;
        const char *function;
-       char *str;
        AST_LIST_ENTRY(logmsg) list;
+       char str[0];
 };
 
 static AST_LIST_HEAD_STATIC(logmsgs, logmsg);
@@ -750,7 +750,6 @@
                                logger_print_verbose(msg);
 
                        /* Free the data since we are done */
-                       free(msg->str);
                        free(msg);
                }
        }
@@ -874,8 +873,20 @@
        if ((level == __LOG_DEBUG) && !ast_strlen_zero(debug_filename) && strcasecmp(debug_filename, file))
                return;
 
+       /* Build string */
+       va_start(ap, fmt);
+       res = ast_dynamic_str_thread_set_va(&buf, 0, &verbose_buf, fmt, ap);
+       va_end(ap);
+
+       /* Copy string over */
+       strcpy(logmsg->str, ast_strdup(buf->str));
+
+       /* If the build failed, then abort and free this structure */
+       if (res == AST_DYNSTR_BUILD_FAILED)
+               return;
+
        /* Create a new logging message */
-       if (!(logmsg = ast_calloc(1, sizeof(*logmsg))))
+       if (!(logmsg = ast_calloc(1, sizeof(*logmsg) + res + 1)))
                return;
 
        /* Set type to be normal */
@@ -892,20 +903,6 @@
        logmsg->line = line;
        logmsg->function = function;
 
-       /* Build string */
-       va_start(ap, fmt);
-       res = ast_dynamic_str_thread_set_va(&buf, 0, &verbose_buf, fmt, ap);
-       va_end(ap);
-
-       /* If the build failed, then abort and free this structure */
-       if (res == AST_DYNSTR_BUILD_FAILED) {
-               free(logmsg);
-               return;
-       }
-
-       /* Copy string over */
-       logmsg->str = ast_strdup(buf->str);
-
        /* Add it to the list at the tail end, and prod the logging thread */
        AST_LIST_LOCK(&logmsgs);
        AST_LIST_INSERT_TAIL(&logmsgs, logmsg, list);
@@ -954,9 +951,23 @@
        if (!(buf = ast_dynamic_str_thread_get(&verbose_buf, VERBOSE_BUF_INIT_SIZE)))
                return;
 
-       if (!(logmsg = ast_calloc(1, sizeof(*logmsg))))
+       /* Set type */
+       logmsg->type = LOGMSG_VERBOSE;
+
+       /* Build string */
+       va_start(ap, fmt);
+       res = ast_dynamic_str_thread_set_va(&buf, 0, &verbose_buf, fmt, ap);
+       va_end(ap);
+
+       /* If the build failed then we can drop this allocated message */
+       if (res == AST_DYNSTR_BUILD_FAILED)
                return;
 
+       if (!(logmsg = ast_calloc(1, sizeof(*logmsg) + res + 1)))
+               return;
+
+       strcpy(logmsg->str, buf->str);
+
        if (ast_opt_timestamp) {
                time_t t;
                struct tm tm;
@@ -971,24 +982,6 @@
                fmt = datefmt;
        }
 
-       /* Set type */
-       logmsg->type = LOGMSG_VERBOSE;
-
-       /* Build string */
-       va_start(ap, fmt);
-       res = ast_dynamic_str_thread_set_va(&buf, 0, &verbose_buf, fmt, ap);
-       va_end(ap);
-
-       /* If the build failed then we can drop this allocated message */
-       if (res == AST_DYNSTR_BUILD_FAILED) {
-               free(logmsg);
-               return;
-       }
-
-       /* Duplicate it in the logging message */
-       logmsg->str = ast_strdup(buf->str);
-       ast_log(LOG_VERBOSE, "%s", buf->str);
-
        /* Add to the list and poke the thread */
        AST_LIST_LOCK(&logmsgs);
        AST_LIST_INSERT_TAIL(&logmsgs, logmsg, list);