Avoid minor leak in parallel pg_dump
authorStephen Frost
Fri, 24 Jan 2014 20:10:08 +0000 (15:10 -0500)
committerStephen Frost
Fri, 24 Jan 2014 20:12:54 +0000 (15:12 -0500)
During parallel pg_dump, a worker process closing the connection caused
a minor memory leak (particularly minor as we are likely about to exit
anyway).  Instead, free the memory in this case prior to returning NULL
to indicate connection closed.

Spotting by the Coverity scanner.

Back patch to 9.3 where this was introduced.

src/bin/pg_dump/parallel.c

index 7208b0fec236e7cff77c799d6b2fb7bd010e70bd..ff777d2b4f4194f90e5dd36e8bd40fcd9477b42a 100644 (file)
@@ -1288,7 +1288,7 @@ readMessageFromPipe(int fd)
 
        /* worker has closed the connection or another error happened */
        if (ret <= 0)
-           return NULL;
+           break;
 
        Assert(ret == 1);
 
@@ -1303,6 +1303,14 @@ readMessageFromPipe(int fd)
            msg = (char *) realloc(msg, bufsize);
        }
    }
+
+   /*
+    * Worker has closed the connection, make sure to clean up before return
+    * since we are not returning msg (but did allocate it).
+    */
+   free(msg);
+
+   return NULL;
 }
 
 #ifdef WIN32