]> granicus.if.org Git - postgresql/commitdiff
Fix file descriptor leak after failure of a \setshell command in pgbench.
authorTom Lane <tgl@sss.pgh.pa.us>
Tue, 16 Dec 2014 18:31:42 +0000 (13:31 -0500)
committerTom Lane <tgl@sss.pgh.pa.us>
Tue, 16 Dec 2014 18:32:38 +0000 (13:32 -0500)
If the called command fails to return data, runShellCommand forgot to
pclose() the pipe before returning.  This is fairly harmless in the current
code, because pgbench would then abandon further processing of that client
thread; so no more than nclients descriptors could be leaked this way.  But
it's not hard to imagine future improvements whereby that wouldn't be true.
In any case, it's sloppy coding, so patch all branches.  Found by Coverity.

contrib/pgbench/pgbench.c

index 2525d9e1529d28ba89a5cddd189481640ec03d95..b695e7f95d7f4077f2df962313125d8132d2c49a 100644 (file)
@@ -691,6 +691,7 @@ runShellCommand(CState *st, char *variable, char **argv, int argc)
        {
                if (!timer_exceeded)
                        fprintf(stderr, "%s: cannot read the result\n", argv[0]);
+               (void) pclose(fp);
                return false;
        }
        if (pclose(fp) < 0)