diff mbox

[API-NEXT,PATCHv9,13/15] linux-gen: _ishm: cleaning remaining block at odp_term_global

Message ID 1480004553-46760-14-git-send-email-christophe.milard@linaro.org
State Accepted
Commit d3a7028a5708506b63dc6a06846cd05c7552bbf4
Headers show

Commit Message

Christophe Milard Nov. 24, 2016, 4:22 p.m. UTC
Remaining (forgotten, not freed) blocks are gathered and related files
cleaned when odp_term_global() is called. An error message is also issued
so the application writters get to know about these blocks

Signed-off-by: Christophe Milard <christophe.milard@linaro.org>

---
 platform/linux-generic/_ishm.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)

-- 
2.7.4
diff mbox

Patch

diff --git a/platform/linux-generic/_ishm.c b/platform/linux-generic/_ishm.c
index 7c373dc..b00f8f1 100644
--- a/platform/linux-generic/_ishm.c
+++ b/platform/linux-generic/_ishm.c
@@ -1505,12 +1505,25 @@  int _odp_ishm_term_local(void)
 int _odp_ishm_term_global(void)
 {
 	int ret = 0;
+	int index;
+	ishm_block_t *block;
 
 	if ((getpid() != odp_global_data.main_pid) ||
 	    (syscall(SYS_gettid) != getpid()))
 		ODP_ERR("odp_term_global() must be performed by the main "
 			"ODP process!\n.");
 
+	/* cleanup possibly non freed memory (and complain a bit): */
+	for (index = 0; index < ISHM_MAX_NB_BLOCKS; index++) {
+		block = &ishm_tbl->block[index];
+		if (block->len != 0) {
+			ODP_ERR("block '%s' (file %s) was never freed "
+				"(cleaning up...).\n",
+				block->name, block->filename);
+			delete_file(block);
+		}
+	}
+
 	/* perform the last thread terminate which was postponed: */
 	ret = do_odp_ishm_term_local();