freedreno: Fix file descriptor leak.
authorVinson Lee <vlee@freedesktop.org>
Tue, 8 Sep 2020 00:23:35 +0000 (17:23 -0700)
committerMarge Bot <eric+marge@anholt.net>
Wed, 9 Sep 2020 21:56:04 +0000 (21:56 +0000)
Fix defects reported by Coverity Scan.

Resource leak (RESOURCE_LEAK)
leaked_handle: Handle variable fd going out of scope leaks the handle.

Argument cannot be negative (NEGATIVE_RETURNS)
negative_returns: fd is passed to a parameter that cannot be negative.

Fixes: 1ea4ef0d3be8 ("freedreno: slurp in decode tools")
Signed-off-by: Vinson Lee <vlee@freedesktop.org>
Reviewed-by: Rob Clark <robdclark@chromium.org>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6642>

src/freedreno/decode/pgmdump.c

index 932fdb5..9bac866 100644 (file)
@@ -405,7 +405,10 @@ static void dump_raw_shader(uint32_t *dwords, uint32_t sizedwords, int n, char *
 
        sprintf(filename, "%.*s-%d.%s", (int)strlen(infile)-3, infile, n, ext);
        fd = open(filename, O_WRONLY | O_TRUNC | O_CREAT, 0644);
-       write(fd, dwords, sizedwords * 4);
+       if (fd != -1) {
+               write(fd, dwords, sizedwords * 4);
+               close(fd);
+       }
 }
 
 static void dump_shaders_a2xx(struct state *state)