From 5281e2d3b9adea8dff1730d78fe94af85582aea8 Mon Sep 17 00:00:00 2001 From: Mounir IDRASSI Date: Wed, 9 Jul 2014 05:32:14 +0200 Subject: Static Code Analysis : fix resource leakage by ensuring that all Windows handles are released properly --- src/Setup/SelfExtract.c | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'src/Setup') diff --git a/src/Setup/SelfExtract.c b/src/Setup/SelfExtract.c index 5be9cd21..a14a0db4 100644 --- a/src/Setup/SelfExtract.c +++ b/src/Setup/SelfExtract.c @@ -150,6 +150,8 @@ static int CompressBuffer (char *out, char *in, int len) if (!CreatePipe (&hChildStdinRead, &((HANDLE) hChildStdinWrite), &securityAttrib, 0)) { PkgError ("Cannot create STDIN pipe."); + CloseHandle(hChildStdoutWrite); + CloseHandle(hChildStdoutRead); return 0; } SetHandleInformation (hChildStdinWrite, HANDLE_FLAG_INHERIT, 0); @@ -166,6 +168,10 @@ static int CompressBuffer (char *out, char *in, int len) if (!CreateProcess (NULL, "gzip --best", NULL, NULL, TRUE, 0, NULL, NULL, &startupInfo, &procInfo)) { PkgError ("Error: Cannot run gzip.\n\nBefore you can create a self-extracting VeraCrypt package, you need to have the open-source 'gzip' compression tool placed in any directory in the search path for executable files (for example, in 'C:\\Windows\\').\n\nNote: gzip can be freely downloaded e.g. from www.gzip.org"); + CloseHandle(hChildStdoutWrite); + CloseHandle(hChildStdoutRead); + CloseHandle(hChildStdinRead); + CloseHandle(hChildStdinWrite); return 0; } @@ -179,6 +185,8 @@ static int CompressBuffer (char *out, char *in, int len) if (!CloseHandle (hChildStdoutWrite)) { PkgError ("Cannot close STDOUT write"); + CloseHandle(hChildStdoutRead); + CloseHandle(hChildStdinRead); return 0; } @@ -198,6 +206,9 @@ static int CompressBuffer (char *out, char *in, int len) else bGzipHeaderRead = TRUE; // Skip the 10-byte gzip header } + + CloseHandle(hChildStdoutRead); + CloseHandle(hChildStdinRead); return res_len - 8; // A gzip stream ends with a CRC-32 hash and a 32-bit size (those 8 bytes need to be chopped off) } -- cgit v1.2.3