Commit c00a0393 authored by Linus Nordberg's avatar Linus Nordberg

Merge branch 'RADSECPROXY-77' into maint-1.6

parents b5da34a3 6c8491ba
...@@ -744,8 +744,11 @@ int msmppdecrypt(uint8_t *text, uint8_t len, uint8_t *shared, uint8_t sharedlen, ...@@ -744,8 +744,11 @@ int msmppdecrypt(uint8_t *text, uint8_t len, uint8_t *shared, uint8_t sharedlen,
} }
struct realm *newrealmref(struct realm *r) { struct realm *newrealmref(struct realm *r) {
if (r) if (r) {
pthread_mutex_lock(&r->refmutex);
r->refcount++; r->refcount++;
pthread_mutex_unlock(&r->refmutex);
}
return r; return r;
} }
...@@ -2122,12 +2125,16 @@ void freerealm(struct realm *realm) { ...@@ -2122,12 +2125,16 @@ void freerealm(struct realm *realm) {
if (!realm) if (!realm)
return; return;
debug(DBG_DBG, "freerealm: called with refcount %d", realm->refcount); 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; return;
free(realm->name); free(realm->name);
free(realm->message); free(realm->message);
regfree(&realm->regex); regfree(&realm->regex);
pthread_mutex_destroy(&realm->refmutex);
pthread_mutex_destroy(&realm->mutex); pthread_mutex_destroy(&realm->mutex);
/* if refcount == 0, all subrealms gone */ /* if refcount == 0, all subrealms gone */
list_destroy(realm->subrealms); list_destroy(realm->subrealms);
...@@ -2183,7 +2190,8 @@ struct realm *addrealm(struct list *realmlist, char *value, char **servers, char ...@@ -2183,7 +2190,8 @@ struct realm *addrealm(struct list *realmlist, char *value, char **servers, char
} }
memset(realm, 0, sizeof(struct realm)); 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"); debugerrno(errno, DBG_ERR, "mutex init failed");
free(realm); free(realm);
realm = NULL; realm = NULL;
......
...@@ -184,6 +184,7 @@ struct realm { ...@@ -184,6 +184,7 @@ struct realm {
uint8_t accresp; uint8_t accresp;
regex_t regex; regex_t regex;
uint32_t refcount; uint32_t refcount;
pthread_mutex_t refmutex;
pthread_mutex_t mutex; pthread_mutex_t mutex;
struct realm *parent; struct realm *parent;
struct list *subrealms; struct list *subrealms;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment