[sr-dev] git:master:6b078c89: Merge pull request #126 from kamailio/coudot/tls_shm_available_bug
Daniel-Constantin Mierla
miconda at gmail.com
Wed Apr 15 11:19:16 CEST 2015
Module: kamailio
Branch: master
Commit: 6b078c89facce89cfcd1e8cd8148f419b63ac5af
URL: https://github.com/kamailio/kamailio/commit/6b078c89facce89cfcd1e8cd8148f419b63ac5af
Author: Daniel-Constantin Mierla <miconda at gmail.com>
Committer: Daniel-Constantin Mierla <miconda at gmail.com>
Date: 2015-04-15T11:19:09+02:00
Merge pull request #126 from kamailio/coudot/tls_shm_available_bug
fix race condition in tls module when checking available memory limits
---
Modified: mem/shm_mem.c
Modified: mem/shm_mem.h
Modified: modules/tls/tls_server.c
---
Diff: https://github.com/kamailio/kamailio/commit/6b078c89facce89cfcd1e8cd8148f419b63ac5af.diff
Patch: https://github.com/kamailio/kamailio/commit/6b078c89facce89cfcd1e8cd8148f419b63ac5af.patch
---
diff --git a/mem/shm_mem.c b/mem/shm_mem.c
index de78213..5b6a0cf 100644
--- a/mem/shm_mem.c
+++ b/mem/shm_mem.c
@@ -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
diff --git a/mem/shm_mem.h b/mem/shm_mem.h
index eadccb5..97032d4 100644
--- a/mem/shm_mem.h
+++ b/mem/shm_mem.h
@@ -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 */
diff --git a/modules/tls/tls_server.c b/modules/tls/tls_server.c
index 1d86140..be020ec 100644
--- a/modules/tls/tls_server.c
+++ b/modules/tls/tls_server.c
@@ -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
More information about the sr-dev
mailing list