Skip to content

Commit f31fc71

Browse files
authored
Move putenv out of the if block (#194)
It turns out that, if we call `putenv` inside the if block, then it is no longer valid out of the block.
1 parent 8f8f632 commit f31fc71

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

dex2oat/src/main/cpp/dex2oat.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,9 @@ int main(int argc, char **argv) {
117117
read_int(sock_fd);
118118
close(sock_fd);
119119

120+
if (hooker_fd == -1) {
121+
PLOGE("failed to read liboat_hook.so");
122+
}
120123
LOGD("sock: %s %d", sock.sun_path + 1, stock_fd);
121124

122125
const char *new_argv[argc + 2];
@@ -131,15 +134,12 @@ int main(int argc, char **argv) {
131134
putenv((char *)libenv);
132135
}
133136

134-
if (hooker_fd > 0) {
135-
// Set LD_PRELOAD to load liboat_hook.so
136-
const int STRING_BUFFER = 50;
137-
char env_str[STRING_BUFFER];
138-
snprintf(env_str, STRING_BUFFER, "LD_PRELOAD=/proc/%d/fd/%d", getpid(), hooker_fd);
139-
putenv(env_str);
140-
} else {
141-
LOGE("Unable to read liboat_hook.so");
142-
}
137+
// Set LD_PRELOAD to load liboat_hook.so
138+
const int STRING_BUFFER = 50;
139+
char env_str[STRING_BUFFER];
140+
snprintf(env_str, STRING_BUFFER, "LD_PRELOAD=/proc/%d/fd/%d", getpid(), hooker_fd);
141+
putenv(env_str);
142+
LOGD("Set env %s", env_str);
143143

144144
fexecve(stock_fd, (char **)new_argv, environ);
145145

0 commit comments

Comments
 (0)