Injection refactoring: code cleanup
authorIgor Kulaychuk <igor.kulaychuk@gmail.com>
Mon, 1 Oct 2018 09:22:46 +0000 (12:22 +0300)
committerPetr Bred/AI Ecosystem Lab /SRR/Staff Engineer/삼성전자 <p.bred@samsung.com>
Mon, 1 Oct 2018 12:33:14 +0000 (15:33 +0300)
Remove gotos, add comments

Change-Id: I87d7be179225c3e4ad5a28d167a862b08f1ce0fb

Signed-off-by: Igor Kulaychuk <igor.kulaychuk@gmail.com>
NativeLauncher/launcher/injection.cc

index 5e18e90..3efd3a9 100644 (file)
@@ -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<inject_func*>(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;
 }