diff mbox

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

Message ID 1475836517-60484-14-git-send-email-christophe.milard@linaro.org
State Superseded
Headers show

Commit Message

Christophe Milard Oct. 7, 2016, 10:35 a.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 | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

-- 
2.7.4
diff mbox

Patch

diff --git a/platform/linux-generic/_ishm.c b/platform/linux-generic/_ishm.c
index 7624eca..11bb316 100644
--- a/platform/linux-generic/_ishm.c
+++ b/platform/linux-generic/_ishm.c
@@ -1435,12 +1435,28 @@  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);
+			if (block->filename[0] != 0)
+				unlink(block->filename);
+			if (block->linkname[0] != 0)
+				unlink(block->linkname);
+		}
+	}
+
 	/* perform the last thread terminate which was postponed: */
 	ret = do_odp_ishm_term_local();