rpcrt4: Fix a file handle leak in RPCRT4_RPCSSOnDemandCall().
Francois Gouget
fgouget at codeweavers.com
Thu Mar 8 08:29:50 CST 2007
Also, RPCRT4_RpcssNPConnect() returns a file handle so treat it as such by checking it against INVALID_HANDLE_VALUE and not NULL.
---
Rob, I hope this makes sense.
dlls/rpcrt4/rpcrt4_main.c | 13 ++++++++-----
dlls/rpcrt4/rpcss_np_client.c | 6 ++----
2 files changed, 10 insertions(+), 9 deletions(-)
diff --git a/dlls/rpcrt4/rpcrt4_main.c b/dlls/rpcrt4/rpcrt4_main.c
index e4191d8..513ff47 100644
--- a/dlls/rpcrt4/rpcrt4_main.c
+++ b/dlls/rpcrt4/rpcrt4_main.c
@@ -710,13 +710,14 @@ static BOOL RPCRT4_StartRPCSS(void)
BOOL RPCRT4_RPCSSOnDemandCall(PRPCSS_NP_MESSAGE msg, char *vardata_payload, PRPCSS_NP_REPLY reply)
{
HANDLE client_handle;
+ BOOL ret;
int i, j = 0;
TRACE("(msg == %p, vardata_payload == %p, reply == %p)\n", msg, vardata_payload, reply);
client_handle = RPCRT4_RpcssNPConnect();
- while (!client_handle) {
+ while (INVALID_HANDLE_VALUE == client_handle) {
/* start the RPCSS process */
if (!RPCRT4_StartRPCSS()) {
ERR("Unable to start RPCSS process.\n");
@@ -726,13 +727,13 @@ BOOL RPCRT4_RPCSSOnDemandCall(PRPCSS_NP_MESSAGE msg, char *vardata_payload, PRPC
for (i = 0; i < 60; i++) {
Sleep(200);
client_handle = RPCRT4_RpcssNPConnect();
- if (client_handle) break;
+ if (INVALID_HANDLE_VALUE != client_handle) break;
}
/* we are only willing to try twice */
if (j++ >= 1) break;
}
- if (!client_handle) {
+ if (INVALID_HANDLE_VALUE == client_handle) {
/* no dice! */
ERR("Unable to connect to RPCSS process!\n");
SetLastError(RPC_E_SERVER_DIED_DNE);
@@ -740,12 +741,14 @@ BOOL RPCRT4_RPCSSOnDemandCall(PRPCSS_NP_MESSAGE msg, char *vardata_payload, PRPC
}
/* great, we're connected. now send the message */
+ ret = TRUE;
if (!RPCRT4_SendReceiveNPMsg(client_handle, msg, vardata_payload, reply)) {
ERR("Something is amiss: RPC_SendReceive failed.\n");
- return FALSE;
+ ret = FALSE;
}
+ CloseHandle(client_handle);
- return TRUE;
+ return ret;
}
#define MAX_RPC_ERROR_TEXT 256
diff --git a/dlls/rpcrt4/rpcss_np_client.c b/dlls/rpcrt4/rpcss_np_client.c
index 73270c6..016f77f 100644
--- a/dlls/rpcrt4/rpcss_np_client.c
+++ b/dlls/rpcrt4/rpcss_np_client.c
@@ -32,7 +32,7 @@ WINE_DEFAULT_DEBUG_CHANNEL(ole);
HANDLE RPCRT4_RpcssNPConnect(void)
{
- HANDLE the_pipe = NULL;
+ HANDLE the_pipe;
DWORD dwmode, wait_result;
HANDLE master_mutex = RPCRT4_GetMasterMutex();
@@ -69,7 +69,6 @@ HANDLE RPCRT4_RpcssNPConnect(void)
if (GetLastError() != ERROR_PIPE_BUSY) {
WARN("Unable to open named pipe %s (assuming unavailable).\n",
debugstr_a(NAME_RPCSS_NAMED_PIPE));
- the_pipe = NULL;
break;
}
@@ -83,13 +82,12 @@ HANDLE RPCRT4_RpcssNPConnect(void)
if (! WaitNamedPipeA(NAME_RPCSS_NAMED_PIPE, MASTER_MUTEX_WAITNAMEDPIPE_TIMEOUT))
{
ERR("Named pipe unavailable after waiting. Something is probably wrong.\n");
- the_pipe = NULL;
break;
}
}
- if (the_pipe) {
+ if (the_pipe != INVALID_HANDLE_VALUE) {
dwmode = PIPE_READMODE_MESSAGE;
/* SetNamedPipeHandleState not implemented ATM, but still seems to work somehow. */
if (! SetNamedPipeHandleState(the_pipe, &dwmode, NULL, NULL))
--
1.4.4.4
More information about the wine-patches
mailing list