bugreport-service: fix memory leak 25/259725/1
authorKarol Lewandowski <k.lewandowsk@samsung.com>
Fri, 11 Jun 2021 10:20:40 +0000 (12:20 +0200)
committerKarol Lewandowski <k.lewandowsk@samsung.com>
Fri, 11 Jun 2021 10:22:50 +0000 (12:22 +0200)
Change-Id: I8609072ca5a0eaf55c613390ece3d58b891e6d51

src/bugreport-service/diagnostics/diagnostics.c

index f20b357..f038cad 100644 (file)
@@ -308,7 +308,7 @@ static int share_file(const char *path)
 {
        assert(path);
 
-       const char *dest_file = get_temp_file_name();
+       char *dest_file = get_temp_file_name();
 
        if (dest_file == NULL)
                return -BR_ERR_INTERNAL;
@@ -317,15 +317,19 @@ static int share_file(const char *path)
 
        if (copy_file(dest_file, path) == -1) {
                _E("copy_file() error");
+               free(dest_file);
                return -BR_ERR_INTERNAL;
        }
 
        int fd = open(dest_file, O_RDONLY);
        if (fd  == -1) {
                _E("open() file: \"%s\" error: %m\n", path);
+               free(dest_file);
                return -BR_ERR_INTERNAL;
        }
+
        unlink(dest_file);
+       free(dest_file);
 
        return fd;
 }