فهرست منبع

Merge branch 'maint'

* maint:
  set_set: Don't try list_delete or free on a NULL old
  set_set: Avoid memory leak if no old value and new value is blank
  set_set: Avoid comparing to a freed pointer
  set_unpack: Avoid unneeded malloc/free when there's no data
  Remove some redundant NULL checks
  Clear FiSH keys when a client quits
  bot_counters can be static
Bryan Drewery 8 سال پیش
والد
کامیت
75189c522d
5فایلهای تغییر یافته به همراه27 افزوده شده و 25 حذف شده
  1. 3 0
      doc/UPDATES.md
  2. 1 0
      src/mod/irc.mod/chan.cc
  3. 1 1
      src/mod/irc.mod/irc.cc
  4. 12 12
      src/set.cc
  5. 10 12
      src/userent.cc

+ 3 - 0
doc/UPDATES.md

@@ -8,6 +8,9 @@
     bots know which bots have which roles. (#39)
   * Add cmd_roles (leaf only) to display roles for a channel. (#39)
 
+# maint
+  * Clear FiSH keys when a client quits.
+
 # 1.4.9
   * Fix various compile warnings and spam
   * Fix ptrace detection on OpenBSD (after 1.4.6 regression for the Linux fix)

+ 1 - 0
src/mod/irc.mod/chan.cc

@@ -3244,6 +3244,7 @@ static int gotquit(char *from, char *msg)
    */
   if (keepnick && !match_my_nick(nick))
     nicks_available(nick);
+  set_fish_key(nick, "");
 #ifdef CACHE
   /* see if they were in our cache at all */
   cache_t *cache = cache_find(nick);

+ 1 - 1
src/mod/irc.mod/irc.cc

@@ -91,7 +91,7 @@ static bool ban_fun = 1;
 static bool prevent_mixing = 1;  /* To prevent mixing old/new modes */
 bool include_lk = 1;      /* For correct calculation
                                  * in real_add_mode. */
-bd::HashTable<bd::String, unsigned long> bot_counters;
+static bd::HashTable<bd::String, unsigned long> bot_counters;
 unsigned long my_cookie_counter = 0;
 
 static std::deque<bd::String> chained_who;

+ 12 - 12
src/set.cc

@@ -416,7 +416,7 @@ sdprintf("var (mem): %s -> %s", var->name, datain ? datain : "(NULL)");
     // Need to reload the server settings since we may want a different list now
     sdprintf("server-use-ssl changed, reprocessing server list");
     variable_t *servers = var_get_var_by_name(get_server_type());
-    var_set_mem(servers, servers->ldata ? servers->ldata : servers->gdata ? servers->gdata : NULL);
+    var_set_mem(servers, servers->ldata ? servers->ldata : servers->gdata);
   }
 
   // Check if should part/join channels based on groups changing
@@ -606,7 +606,7 @@ sdprintf("var: %s (local): %s", var->name, data ? data : "(NULL)");
         var->ldata = NULL;
       /* if ldata is blank, see about setting the memory to the global setting... */
       if (domem && var->mem)
-        var_set_mem(var, var->ldata ? var->ldata : var->gdata ? var->gdata : NULL);
+        var_set_mem(var, var->ldata ? var->ldata : var->gdata);
     } 
   } else if (target == NULL) {
     if (var->ldata)
@@ -795,9 +795,9 @@ static bool var_find_list(const char *botnick, variable_t *var, const char *elem
 
   if (botnick) {                          //fetch data from bot's USERENTRY_SET
     char *botdata = (char *) var_get_bot_data(get_user_by_handle(userlist, (char *) botnick), var->name);
-    olddata = botdata ? botdata : NULL;
+    olddata = botdata;
   } else                                  //use global, no bot specified
-    olddata = var->gdata ? var->gdata : NULL;
+    olddata = var->gdata;
 
   if (!olddata)
     return false;
@@ -832,9 +832,9 @@ static int var_add_list(const char *botnick, variable_t *var, const char *elemen
 
   if (botnick) {                          //fetch data from bot's USERENTRY_SET
     botdata = (char *) var_get_bot_data(get_user_by_handle(userlist, (char *) botnick), var->name, true);
-    olddata = botdata ? botdata : NULL;
+    olddata = botdata;
   } else                                  //use global, no bot specified
-    olddata = var->gdata ? var->gdata : NULL;
+    olddata = var->gdata;
 
   /* Append to the olddata if there...*/
   size_t osiz = olddata ? strlen(olddata) : 0;
@@ -865,9 +865,9 @@ static char *var_rem_list(const char *botnick, variable_t *var, const char *elem
 
   if (botnick) {                          //fetch data from bot's USERENTRY_SET
     botdata = (char *) var_get_bot_data(get_user_by_handle(userlist, (char *) botnick), var->name);
-    olddatacp = botdata ? botdata : NULL;
+    olddatacp = botdata;
   } else                                  //use global, no bot specified
-    olddatacp = var->gdata ? var->gdata : NULL;
+    olddatacp = var->gdata;
 
   if (!olddatacp)
     return 0;
@@ -948,9 +948,9 @@ static void display_set_value(int idx, const variable_t *var, const char *botnic
   if (botnick) {				//fetch data from bot's USERENTRY_SET
     struct userrec *botu = get_user_by_handle(userlist, (char *) botnick);
     const char *botdata = var_get_bot_data(botu, var->name);
-    data = botdata ? botdata : NULL;
+    data = botdata;
   } else {					//use global, no bot specified
-    data = var->gdata ? var->gdata : NULL;
+    data = var->gdata;
   }
 
   if (format) {
@@ -1080,9 +1080,9 @@ int cmd_set_real(const char *botnick, int idx, char *par)
          ) {		//Just display the data
         if (botnick) {				//fetch data from bot's USERENTRY_SET
           botdata = var_get_bot_data(botu, var->name);
-          data = botdata ? botdata : NULL;
+          data = botdata;
         } else 					//use global, no bot specified
-          data = var->gdata ? var->gdata : NULL;
+          data = var->gdata;
        
         if (list && data)
           var_print_list(idx, var->name, data);

+ 10 - 12
src/userent.cc

@@ -274,23 +274,22 @@ static bool set_set(struct userrec *u, struct user_entry *e, void *buf)
   }
 
   /* if we have a new entry and an old entry.. or our new entry is empty -> clear out the old entry */
-  if ((old && old != newxk) || !newxk->data || !newxk->data[0]) {
+  if (old && old != newxk && (!newxk->data || !newxk->data[0])) {
     list_delete((struct list_type **) (&e->u.extra), (struct list_type *) old);
 
     free(old->key);
     free(old->data);
     free(old);
+    old = NULL;
   }
 
   /* add the new entry if it's not empty */
-  if (old != newxk && newxk->data) {
-    if (newxk->data[0]) {
-      list_insert((struct xtra_key **) (&e->u.extra), newxk);
-    } else {
-      free(newxk->data);
-      free(newxk->key);
-      free(newxk);
-    }
+  if ((!old || old != newxk) && newxk->data && newxk->data[0]) {
+    list_insert((struct xtra_key **) (&e->u.extra), newxk);
+  } else {
+    free(newxk->data);
+    free(newxk->key);
+    free(newxk);
   }
   return 1;
 }
@@ -306,15 +305,14 @@ static bool set_unpack(struct userrec *u, struct user_entry *e)
   char *key = NULL, *data = NULL;
 
   while (curr) {
-    t = (struct xtra_key *) calloc(1, sizeof(struct xtra_key));
     data = curr->extra;
     key = newsplit(&data);
     if (data[0]) {
+      t = (struct xtra_key *) calloc(1, sizeof(struct xtra_key));
       t->key = strdup(key);
       t->data = strdup(data);
       list_insert((struct xtra_key **) (&e->u.extra), t);
-    } else
-      free(t);
+    }
     curr = curr->next;
   }