lib/libdsa/dsalib_updown.c | 40 ++++++++++++++++++++++------------------
1 file changed, 22 insertions(+), 18 deletions(-)
New commits:
commit d077f9a3b04998c28d0071b7656c34ca7f07e532
Author: Mark Reynolds <mreynolds(a)redhat.com>
Date: Mon Sep 15 12:19:12 2014 -0400
Ticket 47697 - Resource leak in lib/libdsa/dsalib_updown.c
Bug Description: Windows resource leak in StartNetscapeProgram() where
the FILE handle is not closed.
Fix Description: Close FILE handle.
https://fedorahosted.org/389/ticket/47697
Reviewed by: rmeggins(Thanks!)
diff --git a/lib/libdsa/dsalib_updown.c b/lib/libdsa/dsalib_updown.c
index 0bef3ab..f83719b 100644
--- a/lib/libdsa/dsalib_updown.c
+++ b/lib/libdsa/dsalib_updown.c
@@ -526,10 +526,9 @@ StartNetscapeProgram()
{
char line[BIG_LINE], cmd[BIG_LINE];
char *tmp = ds_get_instance_dir();
-
- CHAR ErrorString[512];
- STARTUPINFO siStartInfo;
- PROCESS_INFORMATION piProcInfo;
+ CHAR ErrorString[512];
+ STARTUPINFO siStartInfo;
+ PROCESS_INFORMATION piProcInfo;
FILE *CmdFile;
ZeroMemory(line, sizeof(line));
@@ -538,7 +537,7 @@ StartNetscapeProgram()
CmdFile = fopen(line, "r");
if (!CmdFile)
- {
+ {
PR_snprintf(ErrorString, sizeof(ErrorString), "Error:Tried to start server
%s "
": Could not open the startup script %s :Error %d. Please "
"run startsrv.bat from the server's root directory.",
@@ -549,34 +548,39 @@ StartNetscapeProgram()
ZeroMemory(cmd, sizeof(cmd));
if (!fread(cmd, 1, BIG_LINE, CmdFile))
- {
+ {
PR_snprintf(ErrorString, sizeof(ErrorString), "Error:Tried to start server
%s "
": Could not read the startup script %s :Error %d. Please "
"run startsrv.bat from the server's root directory.",
ds_get_server_name(), line, errno);
ds_send_error(ErrorString, 0);
+ fclose(CmdFile);
return(DS_SERVER_DOWN);
}
- ZeroMemory(&siStartInfo, sizeof(STARTUPINFO));
- siStartInfo.cb = sizeof(STARTUPINFO);
- siStartInfo.lpReserved = siStartInfo.lpReserved2 = NULL;
- siStartInfo.cbReserved2 = 0;
- siStartInfo.lpDesktop = NULL;
-
- if (!CreateProcess(NULL, cmd, NULL, NULL, FALSE,
- 0, NULL, NULL, &siStartInfo, &piProcInfo))
- {
+ /* We're done with the file handle, close it */
+ fclose(CmdFile);
+
+ ZeroMemory(&siStartInfo, sizeof(STARTUPINFO));
+ siStartInfo.cb = sizeof(STARTUPINFO);
+ siStartInfo.lpReserved = siStartInfo.lpReserved2 = NULL;
+ siStartInfo.cbReserved2 = 0;
+ siStartInfo.lpDesktop = NULL;
+
+ if (!CreateProcess(NULL, cmd, NULL, NULL, FALSE,
+ 0, NULL, NULL, &siStartInfo, &piProcInfo))
+ {
PR_snprintf(ErrorString, sizeof(ErrorString), "Error:Tried to start server
%s "
": Could not start up the startup script %s :Error %d. Please "
"run startsrv.bat from the server's root directory.",
ds_get_server_name(), line, GetLastError());
ds_send_error(ErrorString, 0);
return(DS_SERVER_DOWN);
- }
+ }
+
+ CloseHandle(piProcInfo.hProcess);
+ CloseHandle(piProcInfo.hThread);
- CloseHandle(piProcInfo.hProcess);
- CloseHandle(piProcInfo.hThread);
return(DS_SERVER_UP);
}