]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Use talloc for fifo buffers
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Sat, 27 Jun 2015 01:37:17 +0000 (21:37 -0400)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Sat, 27 Jun 2015 20:38:36 +0000 (16:38 -0400)
src/include/libradius.h
src/lib/fifo.c
src/main/client.c
src/main/threads.c

index 83fc2ea69664aa6aa4ab592dc13aa812098e0409..e032ff8c5d7c954dafa1925e58a5a98493409582 100644 (file)
@@ -902,7 +902,7 @@ int         rbtree_walk(rbtree_t *tree, rb_order_t order, rb_walker_t compare, void *co
  */
 typedef struct fr_fifo_t fr_fifo_t;
 typedef void (*fr_fifo_free_t)(void *);
-fr_fifo_t      *fr_fifo_create(int max_entries, fr_fifo_free_t freeNode);
+fr_fifo_t      *fr_fifo_create(TALLOC_CTX *ctx, int max_entries, fr_fifo_free_t freeNode);
 void           fr_fifo_free(fr_fifo_t *fi);
 int            fr_fifo_push(fr_fifo_t *fi, void *data);
 void           *fr_fifo_pop(fr_fifo_t *fi);
index b71fc5113bb2c7b58c24e07cf970182df33624d4..8c7e0b624582edf79eaa908da1feb66ba1bd4aec 100644 (file)
@@ -36,21 +36,17 @@ struct fr_fifo_t {
 };
 
 
-fr_fifo_t *fr_fifo_create(int max, fr_fifo_free_t freeNode)
+fr_fifo_t *fr_fifo_create(TALLOC_CTX *ctx, int max, fr_fifo_free_t freeNode)
 {
        fr_fifo_t *fi;
 
        if ((max < 2) || (max > (1024 * 1024))) return NULL;
 
-       fi = malloc(sizeof(*fi) + (sizeof(fi->data[0])*max));
+       fi = talloc_zero_size(ctx, (sizeof(*fi) + (sizeof(fi->data[0])*max)));
        if (!fi) return NULL;
-
-       memset(fi, 0, sizeof(*fi));
+       talloc_set_type(fi, fr_fifo_t);
 
        fi->max = max;
-       fi->first = 0;
-       fi->last = 0;
-       fi->num = 0;
        fi->freeNode = freeNode;
 
        return fi;
@@ -77,7 +73,7 @@ void fr_fifo_free(fr_fifo_t *fi)
        }
 
        memset(fi, 0, sizeof(*fi));
-       free(fi);
+       talloc_free(fi);
 }
 
 int fr_fifo_push(fr_fifo_t *fi, void *data)
@@ -137,7 +133,7 @@ int main(int argc, char **argv)
        int i, j, array[MAX];
        fr_fifo_t *fi;
 
-       fi = fr_fifo_create(MAX, NULL);
+       fi = fr_fifo_create(NULL, MAX, NULL);
        if (!fi) fr_exit(1);
 
        for (j = 0; j < 5; j++) {
index be53bf1b20e7fcc19a838d1848eae36d553c8b10..f12650bd5737a251035f103ff85310134f878cde 100644 (file)
@@ -71,7 +71,7 @@ void client_free(RADCLIENT *client)
                time_t now;
 
                if (!deleted_clients) {
-                       deleted_clients = fr_fifo_create(1024, (void (*)(void *))client_free);
+                       deleted_clients = fr_fifo_create(NULL, 1024, (void (*)(void *))client_free);
                        if (!deleted_clients) return; /* MEMLEAK */
                }
 
index 0377ada590aa8f15ded4f2ad5d64a58b9c08c92d..14a773aa48277a22fe8a4a14105a2f4340672e13 100644 (file)
@@ -1008,7 +1008,7 @@ int thread_pool_init(CONF_SECTION *cs, bool *spawn_flag)
         *      Allocate multiple fifos.
         */
        for (i = 0; i < RAD_LISTEN_MAX; i++) {
-               thread_pool.fifo[i] = fr_fifo_create(thread_pool.max_queue_size, NULL);
+               thread_pool.fifo[i] = fr_fifo_create(NULL, thread_pool.max_queue_size, NULL);
                if (!thread_pool.fifo[i]) {
                        ERROR("FATAL: Failed to set up request fifo");
                        return -1;