X-Git-Url: https://git.lttng.org/?p=lttng-tools.git;a=blobdiff_plain;f=src%2Fcommon%2Futils.c;h=e7dccb7b7490cb1c1392461304e70ea7cbf5d390;hp=4e78767dfb46d2c18b47670174a21bbbeafbdfb3;hb=ffb0b851ac47de854df910d226dfd150b32e8bfe;hpb=6c1c0768320135c6936c371b09731851b508c023 diff --git a/src/common/utils.c b/src/common/utils.c index 4e78767df..e7dccb7b7 100644 --- a/src/common/utils.c +++ b/src/common/utils.c @@ -91,6 +91,10 @@ char *utils_partial_realpath(const char *path, char *resolved_path, size_t size) /* Cut the part we will be trying to resolve */ cut_path = strndup(path, next - path); + if (cut_path == NULL) { + PERROR("strndup"); + goto error; + } /* Try to resolve this part */ try_path = realpath((char *)cut_path, NULL); @@ -144,6 +148,10 @@ char *utils_partial_realpath(const char *path, char *resolved_path, size_t size) * path are pointers for the same memory space */ cut_path = strdup(prev); + if (cut_path == NULL) { + PERROR("strdup"); + goto error; + } /* Concatenate the strings */ snprintf(resolved_path, size, "%s%s", try_path_prev, cut_path); @@ -217,7 +225,10 @@ char *utils_expand_path(const char *path) /* We prepare the start_path not containing it */ start_path = strndup(absolute_path, next - absolute_path); - + if (!start_path) { + PERROR("strndup"); + goto error; + } /* And we concatenate it with the part after this string */ snprintf(absolute_path, PATH_MAX, "%s%s", start_path, next + 2); @@ -234,6 +245,10 @@ char *utils_expand_path(const char *path) /* Then we prepare the start_path not containing it */ start_path = strndup(absolute_path, previous - absolute_path); + if (!start_path) { + PERROR("strndup"); + goto error; + } /* And we concatenate it with the part after the '/../' */ snprintf(absolute_path, PATH_MAX, "%s%s", start_path, next + 4); @@ -499,7 +514,9 @@ int utils_create_lock_file(const char *filepath) if (ret) { WARN("Could not get lock file %s, another instance is running.", filepath); - close(fd); + if (close(fd)) { + PERROR("close lock file"); + } fd = ret; goto error; }