[sr-dev] git:master:ef62bfb2: core: mem/tlsf - handle return codes during memory pool init

Daniel-Constantin Mierla miconda at gmail.com
Mon Apr 25 09:46:44 CEST 2022


Module: kamailio
Branch: master
Commit: ef62bfb27514dc7ec3b603bee661cfac18c4fe93
URL: https://github.com/kamailio/kamailio/commit/ef62bfb27514dc7ec3b603bee661cfac18c4fe93

Author: Daniel-Constantin Mierla <miconda at gmail.com>
Committer: Daniel-Constantin Mierla <miconda at gmail.com>
Date: 2022-04-25T09:46:18+02:00

core: mem/tlsf - handle return codes during memory pool init

---

Modified: src/core/mem/tlsf_malloc.c

---

Diff:  https://github.com/kamailio/kamailio/commit/ef62bfb27514dc7ec3b603bee661cfac18c4fe93.diff
Patch: https://github.com/kamailio/kamailio/commit/ef62bfb27514dc7ec3b603bee661cfac18c4fe93.patch

---

diff --git a/src/core/mem/tlsf_malloc.c b/src/core/mem/tlsf_malloc.c
index 19b71a8be3..805ada03cc 100644
--- a/src/core/mem/tlsf_malloc.c
+++ b/src/core/mem/tlsf_malloc.c
@@ -936,7 +936,13 @@ tlsf_t tlsf_create(void* mem)
 tlsf_t tlsf_create_with_pool(void* mem, size_t bytes)
 {
 	tlsf_t tlsf = tlsf_create(mem);
-	tlsf_add_pool(tlsf, (char*)mem + tlsf_size(), bytes - tlsf_size());
+	if(tlsf) {
+		pool_t p;
+		p = tlsf_add_pool(tlsf, (char*)mem + tlsf_size(), bytes - tlsf_size());
+		if(!p) {
+			return NULL;
+		}
+	}
 	return tlsf;
 }
 
@@ -1387,6 +1393,12 @@ int tlsf_malloc_init_pkg_manager(void)
 	_tlsf_pkg_pool = malloc(pkg_mem_size);
 	if (_tlsf_pkg_pool) {
 		_tlsf_pkg_block = tlsf_create_with_pool(_tlsf_pkg_pool, pkg_mem_size);
+		if(_tlsf_pkg_block==NULL) {
+			LM_CRIT("could not create tlsf pkg memory pool\n");
+			fprintf(stderr, "could not create tlsf pkg memory pool: %ld bytes\n",
+							pkg_mem_size);
+			return -1;
+		}
 	} else {
 		LOG(L_CRIT, "could not initialize tlsf pkg memory pool\n");
 		fprintf(stderr, "Too much tlsf pkg memory demanded: %ld bytes\n",
@@ -1639,6 +1651,12 @@ int tlsf_malloc_init_shm_manager(void)
 	_tlsf_shm_pool = shm_core_get_pool();
 	if (_tlsf_shm_pool) {
 		_tlsf_shm_block = tlsf_create_with_pool(_tlsf_shm_pool, shm_mem_size);
+		if(!_tlsf_shm_block) {
+			LM_CRIT("could not create tlsf shm memory pool\n");
+			fprintf(stderr, "could not create tlsf shm memory pool: %ld bytes\n",
+							shm_mem_size);
+			return -1;
+		}
 	} else {
 		LOG(L_CRIT, "could not initialize tlsf shm memory pool\n");
 		fprintf(stderr, "Too much tlsf shm memory demanded: %ld bytes\n",




More information about the sr-dev mailing list