From: Maxim Uvarov <maxim.uva...@linaro.org> Code missed getenv() return code check and did not use value of env variable to change default derection.
Signed-off-by: Maxim Uvarov <maxim.uva...@linaro.org> --- /** Email created from pull request 83 (muvarov:master_shm_dir_fix) ** https://github.com/Linaro/odp/pull/83 ** Patch: https://github.com/Linaro/odp/pull/83.patch ** Base sha: 95ba4b394009d92c29c2e22f0776e90bb4c6edec ** Merge commit sha: a7d94443cbc414cd68dc576b3e3757f65aa9b789 **/ platform/linux-generic/_ishm.c | 15 +++++++++++---- platform/linux-generic/include/odp_internal.h | 1 + 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/platform/linux-generic/_ishm.c b/platform/linux-generic/_ishm.c index cde2dbc3..892e889b 100644 --- a/platform/linux-generic/_ishm.c +++ b/platform/linux-generic/_ishm.c @@ -1442,9 +1442,15 @@ int _odp_ishm_init_global(void) odp_global_data.main_pid = getpid(); odp_global_data.shm_dir = getenv("ODP_SHM_DIR"); - odp_global_data.shm_dir = - calloc(1, sizeof(ISHM_FILENAME_NORMAL_PAGE_DIR)); - sprintf(odp_global_data.shm_dir, "%s", ISHM_FILENAME_NORMAL_PAGE_DIR); + if (odp_global_data.shm_dir) { + odp_global_data.shm_dir_from_env = 1; + } else { + odp_global_data.shm_dir = + calloc(1, sizeof(ISHM_FILENAME_NORMAL_PAGE_DIR)); + sprintf(odp_global_data.shm_dir, "%s", + ISHM_FILENAME_NORMAL_PAGE_DIR); + odp_global_data.shm_dir_from_env = 0; + } ODP_DBG("ishm: using dir %s\n", odp_global_data.shm_dir); @@ -1661,7 +1667,8 @@ int _odp_ishm_term_global(void) if (_odp_ishmphy_unbook_va()) ret |= -1; - free(odp_global_data.shm_dir); + if (!odp_global_data.shm_dir_from_env) + free(odp_global_data.shm_dir); return ret; } diff --git a/platform/linux-generic/include/odp_internal.h b/platform/linux-generic/include/odp_internal.h index dd3374b7..ec17b199 100644 --- a/platform/linux-generic/include/odp_internal.h +++ b/platform/linux-generic/include/odp_internal.h @@ -43,6 +43,7 @@ typedef struct { struct odp_global_data_s { char *shm_dir; /*< directory for odp mmaped files */ + int shm_dir_from_env; /*< overload default with env */ pid_t main_pid; char uid[UID_MAXLEN]; odp_log_func_t log_fn;