rpcrt4: Use a FINALLY block to clean up in do_ndr_client_call().

Signed-off-by: Zebediah Figura <z.figura12@gmail.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Zebediah Figura 2019-05-20 23:30:56 -05:00 committed by Alexandre Julliard
parent ae5f2a8f84
commit 9271efc0c7
1 changed files with 148 additions and 118 deletions

View File

@ -657,6 +657,46 @@ PFORMAT_STRING convert_old_args( PMIDL_STUB_MESSAGE pStubMsg, PFORMAT_STRING pFo
return (PFORMAT_STRING)args;
}
struct ndr_client_call_ctx
{
MIDL_STUB_MESSAGE *stub_msg;
INTERPRETER_OPT_FLAGS Oif_flags;
INTERPRETER_OPT_FLAGS2 ext_flags;
const NDR_PROC_HEADER *proc_header;
void *This;
PFORMAT_STRING handle_format;
handle_t hbinding;
};
static void CALLBACK ndr_client_call_finally(BOOL normal, void *arg)
{
struct ndr_client_call_ctx *ctx = arg;
if (ctx->ext_flags.HasNewCorrDesc)
{
/* free extra correlation package */
NdrCorrelationFree(ctx->stub_msg);
}
if (ctx->Oif_flags.HasPipes)
{
/* NdrPipesDone(...) */
}
/* free the full pointer translation tables */
if (ctx->proc_header->Oi_flags & Oi_FULL_PTR_USED)
NdrFullPointerXlatFree(ctx->stub_msg->FullPtrXlatTables);
/* free marshalling buffer */
if (ctx->proc_header->Oi_flags & Oi_OBJECT_PROC)
NdrProxyFreeBuffer(ctx->This, ctx->stub_msg);
else
{
NdrFreeBuffer(ctx->stub_msg);
client_free_handle(ctx->stub_msg, ctx->proc_header, ctx->handle_format, ctx->hbinding);
}
}
/* Helper for ndr_client_call, to factor out the part that may or may not be
* guarded by a try/except block. */
static LONG_PTR do_ndr_client_call( const MIDL_STUB_DESC *stub_desc, const PFORMAT_STRING format,
@ -664,6 +704,7 @@ static LONG_PTR do_ndr_client_call( const MIDL_STUB_DESC *stub_desc, const PFORM
unsigned short procedure_number, unsigned short stack_size, unsigned int number_of_params,
INTERPRETER_OPT_FLAGS Oif_flags, INTERPRETER_OPT_FLAGS2 ext_flags, const NDR_PROC_HEADER *proc_header )
{
struct ndr_client_call_ctx finally_ctx;
RPC_MESSAGE rpc_msg;
handle_t hbinding = NULL;
/* the value to return to the client from the remote procedure */
@ -683,7 +724,18 @@ static LONG_PTR do_ndr_client_call( const MIDL_STUB_DESC *stub_desc, const PFORM
This = stack_top[0];
NdrProxyInitialize(This, &rpc_msg, stub_msg, stub_desc, procedure_number);
}
else
finally_ctx.stub_msg = stub_msg;
finally_ctx.Oif_flags = Oif_flags;
finally_ctx.ext_flags = ext_flags;
finally_ctx.proc_header = proc_header;
finally_ctx.This = This;
finally_ctx.handle_format = handle_format;
finally_ctx.hbinding = hbinding;
__TRY
{
if (!(proc_header->Oi_flags & Oi_OBJECT_PROC))
NdrClientInitializeNew(&rpc_msg, stub_msg, stub_desc, procedure_number);
stub_msg->StackTop = (unsigned char *)stack_top;
@ -788,30 +840,8 @@ static LONG_PTR do_ndr_client_call( const MIDL_STUB_DESC *stub_desc, const PFORM
TRACE( "UNMARSHAL\n" );
client_do_args(stub_msg, format, STUBLESS_UNMARSHAL, fpu_stack,
number_of_params, (unsigned char *)&retval);
if (ext_flags.HasNewCorrDesc)
{
/* free extra correlation package */
NdrCorrelationFree(stub_msg);
}
if (Oif_flags.HasPipes)
{
/* NdrPipesDone(...) */
}
/* free the full pointer translation tables */
if (proc_header->Oi_flags & Oi_FULL_PTR_USED)
NdrFullPointerXlatFree(stub_msg->FullPtrXlatTables);
/* free marshalling buffer */
if (proc_header->Oi_flags & Oi_OBJECT_PROC)
NdrProxyFreeBuffer(This, stub_msg);
else
{
NdrFreeBuffer(stub_msg);
client_free_handle(stub_msg, proc_header, handle_format, hbinding);
}
__FINALLY_CTX(ndr_client_call_finally, &finally_ctx)
return retval;
}