소스 검색

Merge branch 'server-queue-crash'

* server-queue-crash:
  * Fix queue_server(NEXT) causing memleak, queue truncation, and possibily a crash
  * Server queue code cleanup
Bryan Drewery 16 년 전
부모
커밋
514b325bf1
1개의 변경된 파일13개의 추가작업 그리고 12개의 파일을 삭제
  1. 13 12
      src/mod/server.mod/server.c

+ 13 - 12
src/mod/server.mod/server.c

@@ -292,17 +292,19 @@ void deq_msg()
 #ifdef not_implemented
       if (deq_kick(qdsc[nq].idx)) {
         ++burst;++flood_count;
-        continue;
+        break;
       }
 #endif
       if (fast_deq(nq))
-        continue;
+        break;
       write_to_server(qdsc[nq].q->head->msg, qdsc[nq].q->head->len);
       ++burst;++flood_count;
       if (debug_output)
         putlog(LOG_SRVOUT, "*", "[%c->] %s", qdsc[nq].pfx, qdsc[nq].q->head->msg);
       --(qdsc[nq].q->tot);
       calc_penalty(qdsc[nq].q->head->msg, qdsc[nq].q->head->len);
+
+      // Shift off dequeued message
       q = qdsc[nq].q->head->next;
       free(qdsc[nq].q->head->msg);
       free(qdsc[nq].q->head);
@@ -690,22 +692,21 @@ void queue_server(int which, char *buf, int len)
     }
 
     struct msgq *q = (struct msgq *) my_calloc(1, sizeof(struct msgq));
-    if (qnext)
-      q->next = h->head;
-    else
-      q->next = NULL;
+
     if (h->head) {
-      if (!qnext)
+      if (!qnext) { //Not next, add to end of queue
         h->last->next = q;
+        h->last = q;
+      } else if (qnext) { //Should be next, insert into front of queue
+        q->next = h->head;
+        h->head = q;
+      }
     } else
-      h->head = q;
-    if (qnext)
-       h->head = q;
-    h->last = q;
+      h->head = h->last = q;
     q->len = len;
     q->msg = (char *) my_calloc(1, len + 1);
     strlcpy(q->msg, buf, len + 1);
-    h->tot++;
+    ++(h->tot);
     h->warned = 0;
     double_warned = 0;
   } else {