Commit d3245723 authored by Francois Gouget's avatar Francois Gouget Committed by Alexandre Julliard

rpcrt4: Fix a file handle leak in RPCRT4_RPCSSOnDemandCall().

Also, RPCRT4_RpcssNPConnect() returns a file handle so treat it as such by checking it against INVALID_HANDLE_VALUE and not NULL.
parent 7b89fb5e
......@@ -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
......
......@@ -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))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment