[Reconnoiter-devel] [reconnoiter commit] Reconnoiter branch, master, updated. 60aa58b81f5826158d1b04067717cc454dc1742b

git at labs.omniti.com git at labs.omniti.com
Sun Apr 22 14:43:32 EDT 2012


Pushed by: jesus
The branch, master has been updated
       via  60aa58b81f5826158d1b04067717cc454dc1742b (commit)
       via  1dbb45b9deca8465c32394889ee40088e6297634 (commit)
       via  5fd1894ad04542945430bed21cc582a937f8edcb (commit)
      from  66cf6d4b55d526fdb6724e700480033f198045fa (commit)

Summary of changes:
 src/noit_check.c            |    7 +++++--
 src/noit_check_tools.c      |   16 +++++++++++-----
 src/noit_conf_checks.c      |   11 ++++++++---
 src/noit_console.c          |   17 +++++++++++++----
 src/noit_console_complete.c |   11 +++++++----
 src/noit_console_telnet.c   |    1 +
 src/noitedit/history.c      |    1 +
 src/noitedit/key.c          |    2 +-
 src/noitedit/term.c         |    2 ++
 src/utils/noit_log.c        |   14 +++++++++++---
 10 files changed, 60 insertions(+), 22 deletions(-)

Log:
commit 60aa58b81f5826158d1b04067717cc454dc1742b
Author: Theo Schlossnagle <jesus at omniti.com>
Date:   Sun Apr 22 14:43:28 2012 -0400

    various leaks in the console driver and our fork of libedit. tgetent() still appears to leak, but that might be an ncurses bug

diff --git a/src/noit_console.c b/src/noit_console.c
index b794b24..23302f1 100644
--- a/src/noit_console.c
+++ b/src/noit_console.c
@@ -169,6 +169,7 @@ nc_vprintf(noit_console_closure_t ncct, const char *fmt, va_list arg) {
 }
 int
 nc_write(noit_console_closure_t ncct, const void *buf, int len) {
+  if(len == 0) return 0;
   if(!ncct->outbuf_allocd) {
     ncct->outbuf = malloc(len);
     if(!ncct->outbuf) return 0;
@@ -196,10 +197,16 @@ noit_console_userdata_free(void *data) {
   }
 }
 void
-noit_console_closure_free(noit_console_closure_t ncct) {
+noit_console_closure_free(void *vncct) {
+  noit_console_closure_t ncct = (noit_console_closure_t) vncct;
   noit_log_stream_t lf;
+  noitL(noit_debug, "ncct free(%p)\n", (void *)ncct);
   if(ncct->el) el_end(ncct->el);
-  if(ncct->hist) history_end(ncct->hist);
+  if(ncct->hist) {
+    history_end(ncct->hist);
+    noitL(noit_debug, "ncct free->hist(%p)\n", (void *)ncct->hist);
+    free(ncct->hist);
+  }
   if(ncct->pty_master >= 0) close(ncct->pty_master);
   if(ncct->pty_slave >= 0) close(ncct->pty_slave);
   if(ncct->outbuf) free(ncct->outbuf);
@@ -209,6 +216,7 @@ noit_console_closure_free(noit_console_closure_t ncct) {
     noit_console_state_stack_t *tmp;
     tmp = ncct->state_stack;
     ncct->state_stack = tmp->last;
+    if(tmp->name) free(tmp->name);
     free(tmp);
   }
   lf = noit_log_stream_find(ncct->feed_path);
@@ -356,7 +364,6 @@ socket_error:
 
     /* This removes the log feed which is important to do before calling close */
     eventer_remove_fd(e->fd);
-    if(ncct) noit_console_closure_free(ncct);
     if(ac) acceptor_closure_free(ac);
     e->opset->close(e->fd, &newmask, e);
     return 0;
@@ -364,6 +371,8 @@ socket_error:
 
   if(!ac->service_ctx) {
     ncct = ac->service_ctx = noit_console_closure_alloc();
+    noitL(noit_debug, "ncct alloc() -> %p\n", (void *)ncct);
+    ac->service_ctx_free = noit_console_closure_free;
   }
   if(!ncct->initialized) {
     ncct->e = e;
@@ -446,7 +455,6 @@ socket_error:
     len = e->opset->read(e->fd, sbuf, sizeof(sbuf)-1, &newmask, e);
     if(len == 0 || (len < 0 && errno != EAGAIN)) {
       eventer_remove_fd(e->fd);
-      if(ncct) noit_console_closure_free(ncct);
       if(ac) acceptor_closure_free(ac);
       e->opset->close(e->fd, &newmask, e);
       return 0;
diff --git a/src/noit_console_telnet.c b/src/noit_console_telnet.c
index be5aacd..e13b789 100644
--- a/src/noit_console_telnet.c
+++ b/src/noit_console_telnet.c
@@ -1419,6 +1419,7 @@ clientstat(noit_console_closure_t ncct, int code, int parm1, int parm2)
 	     * Change window size as requested by client.
 	     */
 
+	    memset(&ws, 0, sizeof(ws));
 	    ws.ws_col = parm1;
 	    ws.ws_row = parm2;
 	    ioctl(pty, TIOCSWINSZ, (char *)&ws);
diff --git a/src/noitedit/history.c b/src/noitedit/history.c
index 3340db1..eef260c 100644
--- a/src/noitedit/history.c
+++ b/src/noitedit/history.c
@@ -495,6 +495,7 @@ history_end(History *h)
 
 	if (h->h_next == history_def_next)
 		history_def_clear(h->h_ref, &ev);
+  h_free(h->h_ref);
 }
 
 
diff --git a/src/noitedit/key.c b/src/noitedit/key.c
index 8b57747..3f4e635 100644
--- a/src/noitedit/key.c
+++ b/src/noitedit/key.c
@@ -126,7 +126,7 @@ key_end(EditLine *el)
 
 	el_free((ptr_t) el->el_key.buf);
 	el->el_key.buf = NULL;
-	/* XXX: provide a function to clear the keys */
+	if(el->el_key.map) node__put(el, el->el_key.map);
 	el->el_key.map = NULL;
 }
 
diff --git a/src/noitedit/term.c b/src/noitedit/term.c
index f555543..67bdfcd 100644
--- a/src/noitedit/term.c
+++ b/src/noitedit/term.c
@@ -375,6 +375,8 @@ term_end(EditLine *el)
 	el_free((ptr_t) el->el_term.t_cap);
 	el->el_term.t_cap = NULL;
 	el->el_term.t_loc = 0;
+	el_free((ptr_t) el->el_term.t_fkey);
+	el->el_term.t_fkey = NULL;
 	el_free((ptr_t) el->el_term.t_str);
 	el->el_term.t_str = NULL;
 	el_free((ptr_t) el->el_term.t_val);
diff --git a/src/utils/noit_log.c b/src/utils/noit_log.c
index 4009d4e..5d5d058 100644
--- a/src/utils/noit_log.c
+++ b/src/utils/noit_log.c
@@ -677,6 +677,7 @@ noit_log_init_rwlock(noit_log_stream_t ls) {
 
 noit_log_stream_t
 noit_log_stream_new_on_fd(const char *name, int fd, noit_hash_table *config) {
+  char *lsname;
   noit_log_stream_t ls;
   ls = calloc(1, sizeof(*ls));
   ls->name = strdup(name);
@@ -689,8 +690,10 @@ noit_log_stream_new_on_fd(const char *name, int fd, noit_hash_table *config) {
   /* This double strdup of ls->name is needed, look for the next one
    * for an explanation.
    */
+  lsname = strdup(ls->name);
   if(noit_hash_store(&noit_loggers,
-                     strdup(ls->name), strlen(ls->name), ls) == 0) {
+                     lsname, strlen(ls->name), ls) == 0) {
+    free(lsname);
     free(ls->name);
     free(ls);
     return NULL;
@@ -744,9 +747,13 @@ noit_log_stream_new(const char *name, const char *type, const char *path,
      * noit_log_stream_free up there will sweep our key right our from
      * under us.
      */
+    char *lsname;
+    lsname = strdup(ls->name);
     if(noit_hash_store(&noit_loggers,
-                       strdup(ls->name), strlen(ls->name), ls) == 0)
+                       lsname, strlen(ls->name), ls) == 0) {
+      free(lsname);
       goto freebail;
+    }
     ls->lock = calloc(1, sizeof(*ls->lock));
     noit_log_init_rwlock(ls);
   }
@@ -775,7 +782,7 @@ noit_log_stream_find(const char *name) {
 
 void
 noit_log_stream_remove(const char *name) {
-  noit_hash_delete(&noit_loggers, name, strlen(name), NULL, NULL);
+  noit_hash_delete(&noit_loggers, name, strlen(name), free, NULL);
 }
 
 void
@@ -849,6 +856,7 @@ noit_log_stream_free(noit_log_stream_t ls) {
     struct _noit_log_stream_outlet_list *node;
     if(ls->name) free(ls->name);
     if(ls->path) free(ls->path);
+    if(ls->type) free(ls->type);
     while(ls->outlets) {
       node = ls->outlets->next;
       free(ls->outlets);

commit 1dbb45b9deca8465c32394889ee40088e6297634
Author: Theo Schlossnagle <jesus at omniti.com>
Date:   Sun Apr 22 13:45:45 2012 -0400

    If the period is less than 60000, it is possible to schedule the
    "last check" (as faked at boot) to be in the future, which then
    causes a negative roll in the calculation of the offset causing
    the next check to be scheduled sometime after the death of our sun:
    
    Sun Jul 24 08:13:48 584556061
    
    We should handle this case and appropriately adjust the faked last
    fire time to be in the past by iteratively subtracting period until
    we get there.

diff --git a/src/noit_check.c b/src/noit_check.c
index 3fac6d2..ce9f7af 100644
--- a/src/noit_check.c
+++ b/src/noit_check.c
@@ -221,8 +221,11 @@ noit_check_fake_last_check(noit_check_t *check,
     balance_ms = check_slots_find_smallest(_now->tv_sec+1);
     lc->tv_sec = (lc->tv_sec / 60) * 60 + balance_ms / 1000;
     lc->tv_usec = (balance_ms % 1000) * 1000;
-    if(compare_timeval(*_now, *lc) < 0)
-      sub_timeval(*lc, period, lc);
+    if(compare_timeval(*_now, *lc) < 0) {
+      do {
+        sub_timeval(*lc, period, lc);
+      } while(compare_timeval(*_now, *lc) < 0);
+    }
     else {
       struct timeval test;
       while(1) {
diff --git a/src/noit_check_tools.c b/src/noit_check_tools.c
index 3220391..0072b30 100644
--- a/src/noit_check_tools.c
+++ b/src/noit_check_tools.c
@@ -96,7 +96,7 @@ noit_check_schedule_next(noit_module_t *self,
                          noit_check_t *cause) {
   eventer_t newe;
   struct timeval period, earliest, diff;
-  u_int64_t diffms, periodms, offsetms;
+  int64_t diffms, periodms, offsetms;
   recur_closure_t *rcl;
   int initial = last_check ? 1 : 0;
 
@@ -141,15 +141,21 @@ noit_check_schedule_next(noit_module_t *self,
   periodms = period.tv_sec * 1000 + period.tv_usec / 1000;
 
   newe = eventer_alloc();
-  sub_timeval(earliest, *last_check, &diff);
-  /* calculat the differnet between the initial schedule time and "now" */
-  diffms = diff.tv_sec * 1000 + diff.tv_usec / 1000;
+  /* calculate the differnet between the initial schedule time and "now" */
+  if(compare_timeval(earliest, *last_check) >= 0) {
+    sub_timeval(earliest, *last_check, &diff);
+    diffms = diff.tv_sec * 1000 + diff.tv_usec / 1000;
+  }
+  else {
+    noitL(noit_error, "time is going backwards. abort.\n");
+    abort();
+  }
   /* determine the offset from initial schedule time that would place
    * us at the next period-aligned point past "now" */
   offsetms = ((diffms / periodms) + 1) * periodms;
   diff.tv_sec = offsetms / 1000;
   diff.tv_usec = (offsetms % 1000) * 1000;
- 
+
   memcpy(&newe->whence, last_check, sizeof(*last_check));
   add_timeval(newe->whence, diff, &newe->whence);
 

commit 5fd1894ad04542945430bed21cc582a937f8edcb
Author: Theo Schlossnagle <jesus at omniti.com>
Date:   Sun Apr 22 12:46:08 2012 -0400

    a variety of memory leaks in console commands.

diff --git a/src/noit_conf_checks.c b/src/noit_conf_checks.c
index 89c0a5d..48ba68c 100644
--- a/src/noit_conf_checks.c
+++ b/src/noit_conf_checks.c
@@ -117,9 +117,9 @@ noit_console_mkcheck_xpath(char *xpath, int len,
 static void
 nc_attr_show(noit_console_closure_t ncct, const char *name, xmlNodePtr cnode,
              xmlNodePtr anode, const char *value) {
-  const char *cpath, *apath;
-  cpath = cnode ? (char *)xmlGetNodePath(cnode) : "";
-  apath = anode ? (char *)xmlGetNodePath(anode) : "";
+  char *cpath, *apath;
+  cpath = cnode ? (char *)xmlGetNodePath(cnode) : strdup("");
+  apath = anode ? (char *)xmlGetNodePath(anode) : strdup("");
   nc_printf(ncct, " %s: %s", name, value ? value : "[undef]");
   if(value && cpath && apath) {
     int clen = strlen(cpath);
@@ -133,6 +133,8 @@ nc_attr_show(noit_console_closure_t ncct, const char *name, xmlNodePtr cnode,
     }
   }
   nc_write(ncct, "\n", 1);
+  if(cpath) free(cpath);
+  if(apath) free(apath);
 }
 static void 
 refresh_subchecks(noit_console_closure_t ncct,
@@ -446,6 +448,7 @@ noit_console_show_check(noit_console_closure_t ncct,
       continue;
     }
     nc_printf(ncct, "==== %s ====\n", uuid_conf);
+    free(uuid_conf);
 
 #define MYATTR(a,n,b) _noit_conf_get_string(node, &(n), "@" #a, &(b))
 #define INHERIT(a,n,b) \
@@ -455,6 +458,7 @@ noit_console_show_check(noit_console_closure_t ncct,
   value = NULL; \
   INHERIT(a, anode, value); \
   nc_attr_show(ncct, #a, node, anode, value); \
+  if(value != NULL) free(value); \
 } while(0)
 
     if(!INHERIT(module, mnode, module)) module = NULL;
@@ -463,6 +467,7 @@ noit_console_show_check(noit_console_closure_t ncct,
     else
       nc_printf(ncct, " name: %s [from module]\n", module ? module : "[undef]");
     nc_attr_show(ncct, "module", node, mnode, module);
+    if(module) free(module);
     SHOW_ATTR(target);
     SHOW_ATTR(resolve_rtype);
     SHOW_ATTR(period);
diff --git a/src/noit_console.c b/src/noit_console.c
index d119127..b794b24 100644
--- a/src/noit_console.c
+++ b/src/noit_console.c
@@ -298,6 +298,7 @@ noit_console_dispatch(eventer_t e, const char *buffer,
   if(i>cnt) nc_printf(ncct, "Command length too long.\n");
   else if(i<0) nc_printf(ncct, "Error at offset: %d\n", 0-i);
   else noit_console_state_do(ncct, cnt, cmds);
+  while(cnt>0) free(cmds[--cnt]);
 }
 
 void
diff --git a/src/noit_console_complete.c b/src/noit_console_complete.c
index 60e539a..0a9e919 100644
--- a/src/noit_console_complete.c
+++ b/src/noit_console_complete.c
@@ -96,7 +96,7 @@ static char *
 noitedit_completion_function(EditLine *el, const char *text, int state) {
   noit_console_closure_t ncct;
   const LineInfo *li;
-  char **cmds, *curstr;
+  char **cmds, *curstr, *rv = NULL;
   int len, cnt = 32;
 
   li = el_line(el);
@@ -106,17 +106,20 @@ noitedit_completion_function(EditLine *el, const char *text, int state) {
   curstr[len] = '\0';
 
   cmds = alloca(32 * sizeof(*cmds));
+  cmds[0] = NULL;
   (void) noit_tokenize(curstr, cmds, &cnt);
 
   el_get(el, EL_USERDATA, (void *)&ncct);
 
   if(!strlen(text)) {
-    cmds[cnt++] = "";
+    cmds[cnt++] = strdup("");
   }
-  if(cnt == 32) return NULL;
-  return noit_console_opt_delegate(ncct, ncct->state_stack,
+  if(cnt != 32)
+    rv = noit_console_opt_delegate(ncct, ncct->state_stack,
                                    ncct->state_stack->state,
                                    cnt, cmds, state);
+  if(cmds[0]) while(cnt > 0) free(cmds[--cnt]);
+  return rv;
 }
 static int
 _edit_qsort_string_compare(i1, i2)




hooks/post-receive
-- 
Reconnoiter


More information about the Reconnoiter-devel mailing list