From: Igor Kulaychuk Date: Mon, 1 Oct 2018 09:22:46 +0000 (+0300) Subject: Injection refactoring: code cleanup X-Git-Tag: accepted/tizen/unified/20181001.151003~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=016766f042b94b8d803d7fbaa5b961343fce6880;p=platform%2Fcore%2Fdotnet%2Flauncher.git Injection refactoring: code cleanup Remove gotos, add comments Change-Id: I87d7be179225c3e4ad5a28d167a862b08f1ce0fb Signed-off-by: Igor Kulaychuk --- diff --git a/NativeLauncher/launcher/injection.cc b/NativeLauncher/launcher/injection.cc index 5e18e90..3efd3a9 100644 --- a/NativeLauncher/launcher/injection.cc +++ b/NativeLauncher/launcher/injection.cc @@ -32,22 +32,20 @@ static int injectLibrary(const char path[]) _INFO("Inject %s library", path); - // FIXME: remove RTLD_GLOBAL? + // Current implementation of heaptrack CLR profiler requires RTLD_GLOBAL lib = dlopen(path, RTLD_NOW | RTLD_GLOBAL); if (lib == nullptr) { _ERR("%s", dlerror()); - goto ret; + return res; } inject = reinterpret_cast(dlsym(lib, inject_sym)); if (inject == nullptr) { _ERR("%s is not found in the %s", inject_sym, path); - goto ret; + return res; } res = inject(); - -ret: return res; } @@ -58,11 +56,12 @@ int checkInjection() char* injectableLibs = nullptr; const char *delim = ", "; char *lib = nullptr; + char *saveptr = nullptr; env = getenv("DOTNET_LAUNCHER_INJECT"); if (env == nullptr) { res = 0; - goto ret; + return res; } _INFO("##### Perform injection #########"); @@ -70,12 +69,12 @@ int checkInjection() injectableLibs = strdup(env); if (injectableLibs == nullptr) { _ERR("Fail to allocate memory for injectable library paths\n"); - goto ret; + return res; } res = 0; - lib = strtok(injectableLibs, delim); - for(; lib != nullptr; lib = strtok(nullptr, delim)) { + lib = strtok_r(injectableLibs, delim, &saveptr); + for(; lib != nullptr; lib = strtok_r(nullptr, delim, &saveptr)) { if (injectLibrary(lib) != 0) { res = -1; break; @@ -88,8 +87,6 @@ int checkInjection() _INFO("##### Injection failed #########"); } -ret: free(injectableLibs); - return res; }