summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLinus Nordberg <linus@nordu.net>2017-08-02 10:06:54 +0200
committerLinus Nordberg <linus@nordu.net>2017-08-02 10:06:54 +0200
commitc00a03937712522b5b452ac8cb53fbfe31107028 (patch)
tree9f23324e5445c6cbc39a5460c9cd0714971b956c
parentb5da34a33c2cd07592dcc4d5fadc2cf891526c7f (diff)
parent6c8491ba7ceb656b0d5b329490a4b90c91fb3538 (diff)
Merge branch 'RADSECPROXY-77' into maint-1.6
-rw-r--r--radsecproxy.c14
-rw-r--r--radsecproxy.h1
2 files changed, 12 insertions, 3 deletions
diff --git a/radsecproxy.c b/radsecproxy.c
index b333326..f428e6c 100644
--- a/radsecproxy.c
+++ b/radsecproxy.c
@@ -744,8 +744,11 @@ int msmppdecrypt(uint8_t *text, uint8_t len, uint8_t *shared, uint8_t sharedlen,
}
struct realm *newrealmref(struct realm *r) {
- if (r)
+ if (r) {
+ pthread_mutex_lock(&r->refmutex);
r->refcount++;
+ pthread_mutex_unlock(&r->refmutex);
+ }
return r;
}
@@ -2122,12 +2125,16 @@ void freerealm(struct realm *realm) {
if (!realm)
return;
debug(DBG_DBG, "freerealm: called with refcount %d", realm->refcount);
- if (--realm->refcount)
+ pthread_mutex_lock(&realm->refmutex);
+ --realm->refcount;
+ pthread_mutex_unlock(&realm->refmutex);
+ if (realm->refcount)
return;
free(realm->name);
free(realm->message);
regfree(&realm->regex);
+ pthread_mutex_destroy(&realm->refmutex);
pthread_mutex_destroy(&realm->mutex);
/* if refcount == 0, all subrealms gone */
list_destroy(realm->subrealms);
@@ -2183,7 +2190,8 @@ struct realm *addrealm(struct list *realmlist, char *value, char **servers, char
}
memset(realm, 0, sizeof(struct realm));
- if (pthread_mutex_init(&realm->mutex, NULL)) {
+ if (pthread_mutex_init(&realm->mutex, NULL) ||
+ pthread_mutex_init(&realm->refmutex, NULL)) {
debugerrno(errno, DBG_ERR, "mutex init failed");
free(realm);
realm = NULL;
diff --git a/radsecproxy.h b/radsecproxy.h
index bbb9b58..4019231 100644
--- a/radsecproxy.h
+++ b/radsecproxy.h
@@ -184,6 +184,7 @@ struct realm {
uint8_t accresp;
regex_t regex;
uint32_t refcount;
+ pthread_mutex_t refmutex;
pthread_mutex_t mutex;
struct realm *parent;
struct list *subrealms;