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.mil...@linaro.org>
---
 platform/linux-generic/_ishm.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

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();
 
-- 
2.7.4

Reply via email to