]> git.proxmox.com Git - mirror_frr.git/blobdiff - lib/agentx.c
Merge pull request #9083 from mobash-rasool/pim-upst-3
[mirror_frr.git] / lib / agentx.c
index b5a035ee2be81e31ad558fb4c8760022691ae096..5f865ca2b834476149358c280cb569bcd8d0e98d 100644 (file)
@@ -30,7 +30,7 @@
 #include "smux.h"
 #include "memory.h"
 #include "linklist.h"
-#include "version.h"
+#include "lib/version.h"
 #include "lib_errors.h"
 #include "xref.h"
 
@@ -63,6 +63,8 @@ static int agentx_read(struct thread *t)
        int flags, new_flags = 0;
        int nonblock = false;
        struct listnode *ln = THREAD_ARG(t);
+       struct thread **thr = listgetdata(ln);
+       XFREE(MTYPE_TMP, thr);
        list_delete_node(events, ln);
 
        /* fix for non blocking socket */
@@ -109,7 +111,7 @@ static void agentx_events_update(void)
        struct timeval timeout = {.tv_sec = 0, .tv_usec = 0};
        fd_set fds;
        struct listnode *ln;
-       struct thread *thr;
+       struct thread **thr;
        int fd, thr_fd;
 
        thread_cancel(&timeout_thr);
@@ -125,7 +127,7 @@ static void agentx_events_update(void)
 
        ln = listhead(events);
        thr = ln ? listgetdata(ln) : NULL;
-       thr_fd = thr ? THREAD_FD(thr) : -1;
+       thr_fd = thr ? THREAD_FD(*thr) : -1;
 
        /* "two-pointer" / two-list simultaneous iteration
         * ln/thr/thr_fd point to the next existing event listener to hit while
@@ -135,20 +137,21 @@ static void agentx_events_update(void)
                if (thr_fd == fd) {
                        struct listnode *nextln = listnextnode(ln);
                        if (!FD_ISSET(fd, &fds)) {
-                               thread_cancel(&thr);
+                               thread_cancel(thr);
+                               XFREE(MTYPE_TMP, thr);
                                list_delete_node(events, ln);
                        }
                        ln = nextln;
                        thr = ln ? listgetdata(ln) : NULL;
-                       thr_fd = thr ? THREAD_FD(thr) : -1;
+                       thr_fd = thr ? THREAD_FD(*thr) : -1;
                }
                /* need listener, but haven't hit one where it would be */
                else if (FD_ISSET(fd, &fds)) {
                        struct listnode *newln;
-                       thr = NULL;
-                       thread_add_read(agentx_tm, agentx_read, NULL, fd, &thr);
+                       thr = XCALLOC(MTYPE_TMP, sizeof(struct thread *));
+                       thread_add_read(agentx_tm, agentx_read, NULL, fd, thr);
                        newln = listnode_add_before(events, ln, thr);
-                       thr->arg = newln;
+                       (*thr)->arg = newln;
                }
        }
 
@@ -157,7 +160,8 @@ static void agentx_events_update(void)
        while (ln) {
                struct listnode *nextln = listnextnode(ln);
                thr = listgetdata(ln);
-               thread_cancel(&thr);
+               thread_cancel(thr);
+               XFREE(MTYPE_TMP, thr);
                list_delete_node(events, ln);
                ln = nextln;
        }