]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
valgrind-di-server.c: Fix minor file descriptor leak on error
authorMark Wielaard <mark@klomp.org>
Thu, 2 Dec 2021 13:41:44 +0000 (14:41 +0100)
committerMark Wielaard <mark@klomp.org>
Thu, 2 Dec 2021 13:44:04 +0000 (14:44 +0100)
In handle_transaction when a file descriptor is opened for a file,
but then cannot be stat or the file turns out to be zero size we
leak the file descriptor. Call close (fd) before reporting error.

auxprogs/valgrind-di-server.c

index c6809bc3a9c23541fdca1679ae3d90587c62fdb8..a3357c004a476195c9060b75747a9afd37092ff9 100644 (file)
@@ -774,10 +774,12 @@ static Bool handle_transaction ( int conn_no )
          int r = fstat(fd, &stat_buf);
          if (r != 0) {
             res = mk_Frame_asciiz("FAIL", "OPEN: cannot stat file");
+            close(fd);
             ok = False;
          }
          if (ok && stat_buf.st_size == 0) {
             res = mk_Frame_asciiz("FAIL", "OPEN: file has zero size");
+            close(fd);
             ok = False;
          }
          if (ok) {