Commit 99e93109 authored by Pekka Pessi's avatar Pekka Pessi

su: fixing handle leak with pthread_mutex_destroy()/pthread_cond_destroy()

Thanks for Maxim Zaikin for reporting the problem.

darcs-hash:20070130193708-65a35-5d618ca123a85cb74c2ed63fa1742dbf8d4ac023.gz
parent 0169e883
...@@ -196,6 +196,8 @@ void (*su_home_unlocker)(void *mutex); ...@@ -196,6 +196,8 @@ void (*su_home_unlocker)(void *mutex);
void (*su_home_mutex_locker)(void *mutex); void (*su_home_mutex_locker)(void *mutex);
void (*su_home_mutex_unlocker)(void *mutex); void (*su_home_mutex_unlocker)(void *mutex);
void (*su_home_destroy_mutexes)(void *mutex);
#define MEMLOCK(h) \ #define MEMLOCK(h) \
(((h) && (h)->suh_lock ? su_home_locker((h)->suh_lock) : (void)0), (h)->suh_blocks) (((h) && (h)->suh_lock ? su_home_locker((h)->suh_lock) : (void)0), (h)->suh_blocks)
#define UNLOCK(h) (((h) && (h)->suh_lock ? su_home_unlocker((h)->suh_lock) : (void)0), NULL) #define UNLOCK(h) (((h) && (h)->suh_lock ? su_home_unlocker((h)->suh_lock) : (void)0), NULL)
...@@ -949,6 +951,9 @@ void _su_home_deinit(su_home_t *home) ...@@ -949,6 +951,9 @@ void _su_home_deinit(su_home_t *home)
free(b); free(b);
home->suh_blocks = NULL; home->suh_blocks = NULL;
if (home->suh_lock)
su_home_destroy_mutexes(home->suh_lock);
} }
home->suh_lock = NULL; home->suh_lock = NULL;
......
...@@ -46,6 +46,8 @@ extern void (*su_home_unlocker)(void *mutex); ...@@ -46,6 +46,8 @@ extern void (*su_home_unlocker)(void *mutex);
extern void (*su_home_mutex_locker)(void *mutex); extern void (*su_home_mutex_locker)(void *mutex);
extern void (*su_home_mutex_unlocker)(void *mutex); extern void (*su_home_mutex_unlocker)(void *mutex);
extern void (*su_home_destroy_mutexes)(void *mutex);
/** Mutex */ /** Mutex */
static void mutex_locker(void *_mutex) static void mutex_locker(void *_mutex)
{ {
...@@ -58,6 +60,14 @@ static void mutex_unlocker(void *_mutex) ...@@ -58,6 +60,14 @@ static void mutex_unlocker(void *_mutex)
pthread_mutex_t *mutex = _mutex; pthread_mutex_t *mutex = _mutex;
pthread_mutex_unlock(mutex + 1); pthread_mutex_unlock(mutex + 1);
} }
static void mutex_destroy(void *_mutex)
{
pthread_mutex_t *mutex = _mutex;
pthread_mutex_destroy(mutex + 0);
pthread_mutex_destroy(mutex + 1);
}
#endif #endif
...@@ -65,7 +75,7 @@ static void mutex_unlocker(void *_mutex) ...@@ -65,7 +75,7 @@ static void mutex_unlocker(void *_mutex)
* *
* Convert a memory home object as thread-safe by allocating mutexes and * Convert a memory home object as thread-safe by allocating mutexes and
* modifying function pointers in su_alloc.c module. * modifying function pointers in su_alloc.c module.
*
* @param home memory home object to be converted thread-safe. * @param home memory home object to be converted thread-safe.
* *
* @retval 0 when successful, * @retval 0 when successful,
...@@ -94,6 +104,7 @@ int su_home_threadsafe(su_home_t *home) ...@@ -94,6 +104,7 @@ int su_home_threadsafe(su_home_t *home)
su_home_mutex_unlocker = mutex_unlocker; su_home_mutex_unlocker = mutex_unlocker;
su_home_locker = (void (*)(void *))pthread_mutex_lock; su_home_locker = (void (*)(void *))pthread_mutex_lock;
su_home_unlocker = (void (*)(void *))pthread_mutex_unlock; su_home_unlocker = (void (*)(void *))pthread_mutex_unlock;
su_home_destroy_mutexes = mutex_destroy;
} }
mutex = su_alloc(home, 2 * sizeof (pthread_mutex_t)); mutex = su_alloc(home, 2 * sizeof (pthread_mutex_t));
......
...@@ -186,6 +186,8 @@ void su_pthread_port_deinit(su_port_t *self) ...@@ -186,6 +186,8 @@ void su_pthread_port_deinit(su_port_t *self)
su_close(self->sup_mbox[1]); self->sup_mbox[1] = INVALID_SOCKET; su_close(self->sup_mbox[1]); self->sup_mbox[1] = INVALID_SOCKET;
#endif #endif
pthread_mutex_destroy(self->sup_mutex);
su_base_port_deinit(self); su_base_port_deinit(self);
} }
......
...@@ -1087,6 +1087,10 @@ static void su_clone_xyzzy(su_root_magic_t *m, ...@@ -1087,6 +1087,10 @@ static void su_clone_xyzzy(su_root_magic_t *m,
su_cloned_t *sc) su_cloned_t *sc)
{ {
su_root_destroy(sc->sc_root); su_root_destroy(sc->sc_root);
pthread_mutex_destroy(sc->sc_pause);
pthread_cond_destroy(sc->sc_resume);
if (sc->sc_wait) if (sc->sc_wait)
*sc->sc_wait = 0; *sc->sc_wait = 0;
} }
...@@ -1193,6 +1197,9 @@ int su_clone_start(su_root_t *parent, ...@@ -1193,6 +1197,9 @@ int su_clone_start(su_root_t *parent,
} }
pthread_mutex_unlock(&arg.mutex); pthread_mutex_unlock(&arg.mutex);
pthread_mutex_destroy(&arg.mutex);
pthread_cond_destroy(&arg.cv);
if (arg.retval != 0) { if (arg.retval != 0) {
if (thread_created) if (thread_created)
pthread_join(tid, NULL); pthread_join(tid, NULL);
......
...@@ -48,7 +48,6 @@ char const *name = "su_root_test"; ...@@ -48,7 +48,6 @@ char const *name = "su_root_test";
typedef struct root_test_s root_test_t; typedef struct root_test_s root_test_t;
typedef struct test_ep_s test_ep_t; typedef struct test_ep_s test_ep_t;
typedef struct test_ep_s test_ep_at[1];
#define SU_ROOT_MAGIC_T root_test_t #define SU_ROOT_MAGIC_T root_test_t
#define SU_WAKEUP_ARG_T test_ep_t #define SU_WAKEUP_ARG_T test_ep_t
...@@ -66,6 +65,8 @@ struct test_ep_s { ...@@ -66,6 +65,8 @@ struct test_ep_s {
su_sockaddr_t addr[1]; su_sockaddr_t addr[1];
}; };
typedef struct test_ep_s test_ep_at[1];
struct root_test_s { struct root_test_s {
su_home_t rt_home[1]; su_home_t rt_home[1];
int rt_flags; int rt_flags;
......
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