Skip to content

Commit b3a9ad3

Browse files
committed
util: Handle errors from realpath
realpath() can fail and return NULL. Recent versions of Glibc, including the one included in Ubuntu 20.04 on ARM, tag realpath such that the compiler will emit a warning if the return code is ignored. In addition to fixing a real issue, this patch silences an ignored return value warnig. Signed-off-by: Brian Barrett <bbarrett@amazon.com>
1 parent bf75faf commit b3a9ad3

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

opal/util/path.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -393,10 +393,15 @@ char *opal_find_absolute_path(char *app_name)
393393

394394
if (NULL != abs_app_name) {
395395
char *resolved_path = (char *) malloc(OPAL_PATH_MAX);
396-
realpath(abs_app_name, resolved_path);
396+
char *ret;
397+
ret = realpath(abs_app_name, resolved_path);
397398
if (abs_app_name != app_name) {
398399
free(abs_app_name);
399400
}
401+
if (NULL == ret) {
402+
free(resolved_path);
403+
resolved_path = NULL;
404+
}
400405
return resolved_path;
401406
}
402407
return NULL;

0 commit comments

Comments
 (0)