Skip to content

Commit

Permalink
Merge pull request #126 from kamailio/coudot/tls_shm_available_bug
Browse files Browse the repository at this point in the history
fix race condition in tls module when checking available memory limits
  • Loading branch information
miconda committed Apr 15, 2015
2 parents 1f29210 + 1fe36fa commit 6b078c8
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
8 changes: 8 additions & 0 deletions mem/shm_mem.c
Expand Up @@ -254,5 +254,13 @@ void shm_mem_destroy(void)
#endif
}

inline unsigned long safe_shm_available()
{
unsigned long ret;
shm_lock();
ret = shm_available();
shm_unlock();
return ret;
}

#endif
5 changes: 5 additions & 0 deletions mem/shm_mem.h
Expand Up @@ -312,6 +312,11 @@ do{\

#endif /* ! SHM_SAFE_MALLOC */

/* multi-process safe version of shm_available()
*/
inline unsigned long safe_shm_available();


#endif /* shm_mem_h */

#endif /* SHM_MEM */
Expand Down
4 changes: 2 additions & 2 deletions modules/tls/tls_server.c
Expand Up @@ -59,10 +59,10 @@ int tls_run_event_routes(struct tcp_connection *c);
/* low memory treshold for openssl bug #1491 workaround */
#define LOW_MEM_NEW_CONNECTION_TEST() \
(cfg_get(tls, tls_cfg, low_mem_threshold1) && \
(shm_available() < cfg_get(tls, tls_cfg, low_mem_threshold1)))
(safe_shm_available() < cfg_get(tls, tls_cfg, low_mem_threshold1)))
#define LOW_MEM_CONNECTED_TEST() \
(cfg_get(tls, tls_cfg, low_mem_threshold2) && \
(shm_available() < cfg_get(tls, tls_cfg, low_mem_threshold2)))
(safe_shm_available() < cfg_get(tls, tls_cfg, low_mem_threshold2)))

#define TLS_RD_MBUF_SZ 65536
#define TLS_WR_MBUF_SZ 65536
Expand Down

0 comments on commit 6b078c8

Please sign in to comment.