diff options
author | Linus Nordberg <linus@nordu.net> | 2017-07-28 10:04:29 +0200 |
---|---|---|
committer | Linus Nordberg <linus@nordu.net> | 2017-07-28 10:04:29 +0200 |
commit | 6c8491ba7ceb656b0d5b329490a4b90c91fb3538 (patch) | |
tree | de1a40095cf0663a1b985ac06e2c5928fb68233b /radsecproxy.c | |
parent | 9a565fe0289c55700677e7a6d8446a1de1e77e9e (diff) |
Add mutex guarding realm refcount.RADSECPROXY-77
Diffstat (limited to 'radsecproxy.c')
-rw-r--r-- | radsecproxy.c | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/radsecproxy.c b/radsecproxy.c index 815e927..7029d8a 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; } @@ -2120,12 +2123,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); @@ -2181,7 +2188,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; |