From d112a813e9aee430ada7db47138cbae1baf74a84 Mon Sep 17 00:00:00 2001 From: Jordan Lee Date: Sun, 25 Aug 2013 16:27:19 +0000 Subject: [PATCH] make accessing tr_list's recycle nodes threadsafe. patch by mike.did, fixes #5352 --- libtransmission/list.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/libtransmission/list.c b/libtransmission/list.c index 3d3e51699..e39749011 100644 --- a/libtransmission/list.c +++ b/libtransmission/list.c @@ -12,12 +12,24 @@ #include "transmission.h" #include "list.h" +#include "platform.h" #include "utils.h" static const tr_list TR_LIST_CLEAR = { NULL, NULL, NULL }; static tr_list * recycled_nodes = NULL; +static tr_lock* +getRecycledNodesLock (void) +{ + static tr_lock * l = NULL; + + if (!l) + l = tr_lockNew (); + + return l; +} + static tr_list* node_alloc (void) { @@ -29,8 +41,10 @@ node_alloc (void) } else { + tr_lockLock (getRecycledNodesLock ()); ret = recycled_nodes; recycled_nodes = recycled_nodes->next; + tr_lockUnlock (getRecycledNodesLock ()); } *ret = TR_LIST_CLEAR; @@ -43,8 +57,10 @@ node_free (tr_list* node) if (node != NULL) { *node = TR_LIST_CLEAR; + tr_lockLock (getRecycledNodesLock ()); node->next = recycled_nodes; recycled_nodes = node; + tr_lockUnlock (getRecycledNodesLock ()); } }