Cleanup: Unchecked close() return value in utils_create_lock_file()
[lttng-tools.git] / src / common / utils.c
index 1d07cb31cc01511aedb781124de609277410075d..e7dccb7b7490cb1c1392461304e70ea7cbf5d390 100644 (file)
@@ -18,6 +18,7 @@
  */
 
 #define _GNU_SOURCE
+#define _LGPL_SOURCE
 #include <assert.h>
 #include <ctype.h>
 #include <fcntl.h>
@@ -90,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);
@@ -143,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);
@@ -216,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);
 
@@ -233,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);
@@ -498,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;
        }
This page took 0.024319 seconds and 4 git commands to generate.