Signed-off-by: Zebediah Figura z.figura12@gmail.com --- dlls/rpcrt4/tests/ndr_marshall.c | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-)
diff --git a/dlls/rpcrt4/tests/ndr_marshall.c b/dlls/rpcrt4/tests/ndr_marshall.c index 21baba7..586a7ef 100644 --- a/dlls/rpcrt4/tests/ndr_marshall.c +++ b/dlls/rpcrt4/tests/ndr_marshall.c @@ -35,6 +35,7 @@ #include "rpcdce.h" #include "rpcproxy.h" #include "midles.h" +#include "ndrtypes.h"
static int my_alloc_called; static int my_free_called; @@ -154,17 +155,17 @@ static void test_ndr_simple_type(void) StubMsg.BufferLength = 16; StubMsg.RpcMsg->Buffer = StubMsg.BufferStart = StubMsg.Buffer = HeapAlloc(GetProcessHeap(), 0, StubMsg.BufferLength); l = 0xcafebabe; - NdrSimpleTypeMarshall(&StubMsg, (unsigned char*)&l, 8 /* FC_LONG */); + NdrSimpleTypeMarshall(&StubMsg, (unsigned char*)&l, FC_LONG); ok(StubMsg.Buffer == StubMsg.BufferStart + 4, "%p %p\n", StubMsg.Buffer, StubMsg.BufferStart); ok(*(LONG*)StubMsg.BufferStart == l, "%d\n", *(LONG*)StubMsg.BufferStart);
StubMsg.Buffer = StubMsg.BufferStart + 1; - NdrSimpleTypeMarshall(&StubMsg, (unsigned char*)&l, 8 /* FC_LONG */); + NdrSimpleTypeMarshall(&StubMsg, (unsigned char*)&l, FC_LONG); ok(StubMsg.Buffer == StubMsg.BufferStart + 8, "%p %p\n", StubMsg.Buffer, StubMsg.BufferStart); ok(*(LONG*)(StubMsg.BufferStart + 4) == l, "%d\n", *(LONG*)StubMsg.BufferStart);
StubMsg.Buffer = StubMsg.BufferStart + 1; - NdrSimpleTypeUnmarshall(&StubMsg, (unsigned char*)&l2, 8 /* FC_LONG */); + NdrSimpleTypeUnmarshall(&StubMsg, (unsigned char*)&l2, FC_LONG); ok(StubMsg.Buffer == StubMsg.BufferStart + 8, "%p %p\n", StubMsg.Buffer, StubMsg.BufferStart); ok(l2 == l, "%d\n", l2);
@@ -230,7 +231,7 @@ static void test_pointer_marshal(const unsigned char *formattypes, size = NdrPointerMemorySize( &StubMsg, formattypes ); ok(size == StubMsg.MemorySize, "%s: mem size %u size %u\n", msgpfx, StubMsg.MemorySize, size); ok(StubMsg.Buffer - StubMsg.BufferStart == wiredatalen, "%s: Buffer %p Start %p len %d\n", msgpfx, StubMsg.Buffer, StubMsg.BufferStart, wiredatalen); - if(formattypes[1] & 0x10 /* FC_POINTER_DEREF */) + if (formattypes[1] & FC_POINTER_DEREF) ok(size == srcsize + sizeof(void *), "%s: mem size %u\n", msgpfx, size); else ok(size == srcsize, "%s: mem size %u\n", msgpfx, size); @@ -240,7 +241,7 @@ static void test_pointer_marshal(const unsigned char *formattypes, size = NdrPointerMemorySize( &StubMsg, formattypes ); ok(size == StubMsg.MemorySize, "%s: mem size %u size %u\n", msgpfx, StubMsg.MemorySize, size); ok(StubMsg.Buffer - StubMsg.BufferStart == wiredatalen, "%s: Buffer %p Start %p len %d\n", msgpfx, StubMsg.Buffer, StubMsg.BufferStart, wiredatalen); - if(formattypes[1] & 0x10 /* FC_POINTER_DEREF */) + if (formattypes[1] & FC_POINTER_DEREF) ok(size == srcsize + sizeof(void *) + 16, "%s: mem size %u\n", msgpfx, size); else ok(size == srcsize + 16, "%s: mem size %u\n", msgpfx, size); @@ -250,19 +251,19 @@ static void test_pointer_marshal(const unsigned char *formattypes, size = NdrPointerMemorySize( &StubMsg, formattypes ); ok(size == StubMsg.MemorySize, "%s: mem size %u size %u\n", msgpfx, StubMsg.MemorySize, size); ok(StubMsg.Buffer - StubMsg.BufferStart == wiredatalen, "%s: Buffer %p Start %p len %d\n", msgpfx, StubMsg.Buffer, StubMsg.BufferStart, wiredatalen); - if(formattypes[1] & 0x10 /* FC_POINTER_DEREF */) + if (formattypes[1] & FC_POINTER_DEREF) ok(size == srcsize + sizeof(void *) + (srcsize == 8 ? 8 : sizeof(void *)), "%s: mem size %u\n", msgpfx, size); else ok(size == srcsize + (srcsize == 8 ? 8 : sizeof(void *)), "%s: mem size %u\n", msgpfx, size);
size = srcsize; - if(formattypes[1] & 0x10) size += 4; + if (formattypes[1] & FC_POINTER_DEREF) size += 4;
StubMsg.Buffer = StubMsg.BufferStart; StubMsg.MemorySize = 0; mem_orig = mem = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, size);
- if(formattypes[1] & 0x10 /* FC_POINTER_DEREF */) + if (formattypes[1] & FC_POINTER_DEREF) *(void**)mem = NULL; ptr = NdrPointerUnmarshall( &StubMsg, &mem, formattypes, 0 ); ok(ptr == NULL, "%s: ret %p\n", msgpfx, ptr); @@ -275,7 +276,7 @@ static void test_pointer_marshal(const unsigned char *formattypes,
/* reset the buffer and call with must alloc */ StubMsg.Buffer = StubMsg.BufferStart; - if(formattypes[1] & 0x10 /* FC_POINTER_DEREF */) + if (formattypes[1] & FC_POINTER_DEREF) *(void**)mem = NULL; ptr = NdrPointerUnmarshall( &StubMsg, &mem, formattypes, 1 ); ok(ptr == NULL, "%s: ret %p\n", msgpfx, ptr); @@ -291,7 +292,7 @@ todo_wine { ok(my_alloc_called == num_additional_allocs, "%s: my_alloc got called %d times\n", msgpfx, my_alloc_called); } my_alloc_called = 0; - if(formattypes[0] != 0x11 /* FC_RP */) + if (formattypes[0] != FC_RP) { /* now pass the address of a NULL ptr */ mem = NULL; @@ -314,14 +315,15 @@ todo_wine { StubMsg.IsClient = 0; ptr = NdrPointerUnmarshall( &StubMsg, &mem, formattypes, 0 ); ok(ptr == NULL, "%s: ret %p\n", msgpfx, ptr); - if (formattypes[2] == 0xd /* FC_ENUM16 */) + if (formattypes[2] == FC_ENUM16) ok(mem != StubMsg.BufferStart + wiredatalen - srcsize, "%s: mem points to buffer %p %p\n", msgpfx, mem, StubMsg.BufferStart); else ok(mem == StubMsg.BufferStart + wiredatalen - srcsize, "%s: mem doesn't point to buffer %p %p\n", msgpfx, mem, StubMsg.BufferStart); ok(!cmp(mem, memsrc, size), "%s: incorrectly unmarshaled\n", msgpfx); ok(StubMsg.Buffer - StubMsg.BufferStart == wiredatalen, "%s: Buffer %p Start %p len %d\n", msgpfx, StubMsg.Buffer, StubMsg.BufferStart, wiredatalen); ok(StubMsg.MemorySize == 0, "%s: memorysize %d\n", msgpfx, StubMsg.MemorySize); - if (formattypes[2] != 0xd /* FC_ENUM16 */) { + if (formattypes[2] != FC_ENUM16) + { ok(my_alloc_called == num_additional_allocs, "%s: my_alloc got called %d times\n", msgpfx, my_alloc_called); my_alloc_called = 0; }
Signed-off-by: Zebediah Figura z.figura12@gmail.com --- dlls/rpcrt4/tests/ndr_marshall.c | 58 +++++++++++++++++++++++++++++++--------- 1 file changed, 46 insertions(+), 12 deletions(-)
diff --git a/dlls/rpcrt4/tests/ndr_marshall.c b/dlls/rpcrt4/tests/ndr_marshall.c index 586a7ef..2938b87 100644 --- a/dlls/rpcrt4/tests/ndr_marshall.c +++ b/dlls/rpcrt4/tests/ndr_marshall.c @@ -187,7 +187,6 @@ static void test_pointer_marshal(const unsigned char *formattypes, void *ptr; unsigned char *mem, *mem_orig;
- my_alloc_called = my_free_called = 0; if(!cmp) cmp = memcmp;
@@ -261,8 +260,10 @@ static void test_pointer_marshal(const unsigned char *formattypes,
StubMsg.Buffer = StubMsg.BufferStart; StubMsg.MemorySize = 0; - mem_orig = mem = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, size); - + /* Using my_alloc() here is necessary to prevent a crash in Windows 7+. */ + mem_orig = mem = my_alloc(size); + memset(mem, 0, size); + my_alloc_called = my_free_called = 0; if (formattypes[1] & FC_POINTER_DEREF) *(void**)mem = NULL; ptr = NdrPointerUnmarshall( &StubMsg, &mem, formattypes, 0 ); @@ -271,11 +272,24 @@ static void test_pointer_marshal(const unsigned char *formattypes, ok(!cmp(mem, memsrc, srcsize), "%s: incorrectly unmarshaled\n", msgpfx); ok(StubMsg.Buffer - StubMsg.BufferStart == wiredatalen, "%s: Buffer %p Start %p len %d\n", msgpfx, StubMsg.Buffer, StubMsg.BufferStart, wiredatalen); ok(StubMsg.MemorySize == 0, "%s: memorysize %d\n", msgpfx, StubMsg.MemorySize); - ok(my_alloc_called == num_additional_allocs, "%s: my_alloc got called %d times\n", msgpfx, my_alloc_called); - my_alloc_called = 0; + ok(my_alloc_called == num_additional_allocs, "%s: my_alloc got called %d times\n", msgpfx, my_alloc_called); + /* On Windows 7+ unmarshalling may involve calls to NdrFree, for unclear reasons. */ + my_free_called = 0; + + NdrPointerFree(&StubMsg, mem, formattypes); + if ((formattypes[1] & FC_ALLOCED_ON_STACK) && (formattypes[1] & FC_POINTER_DEREF)) + { + /* In this case the top-level pointer is not freed. */ + ok(my_free_called == num_additional_allocs, "%s: my_free got called %d times\n", msgpfx, my_free_called); + HeapFree(GetProcessHeap(), 0, mem); + } + else + ok(my_free_called == 1 + num_additional_allocs, "%s: my_free got called %d times\n", msgpfx, my_free_called);
/* reset the buffer and call with must alloc */ + my_alloc_called = my_free_called = 0; StubMsg.Buffer = StubMsg.BufferStart; + mem_orig = mem = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, size); if (formattypes[1] & FC_POINTER_DEREF) *(void**)mem = NULL; ptr = NdrPointerUnmarshall( &StubMsg, &mem, formattypes, 1 ); @@ -291,11 +305,23 @@ todo_wine { todo_wine { ok(my_alloc_called == num_additional_allocs, "%s: my_alloc got called %d times\n", msgpfx, my_alloc_called); } - my_alloc_called = 0; + ok(!my_free_called, "%s: my_free got called %d times\n", msgpfx, my_free_called); + + NdrPointerFree(&StubMsg, mem, formattypes); + if ((formattypes[1] & FC_ALLOCED_ON_STACK) && (formattypes[1] & FC_POINTER_DEREF)) + { + /* In this case the top-level pointer is not freed. */ + ok(my_free_called == num_additional_allocs, "%s: my_free got called %d times\n", msgpfx, my_free_called); + HeapFree(GetProcessHeap(), 0, mem); + } + else + ok(my_free_called == 1 + num_additional_allocs, "%s: my_free got called %d times\n", msgpfx, my_free_called); + if (formattypes[0] != FC_RP) { /* now pass the address of a NULL ptr */ mem = NULL; + my_alloc_called = my_free_called = 0; StubMsg.Buffer = StubMsg.BufferStart; ptr = NdrPointerUnmarshall( &StubMsg, &mem, formattypes, 0 ); ok(ptr == NULL, "%s: ret %p\n", msgpfx, ptr); @@ -329,7 +355,6 @@ todo_wine { } } } - HeapFree(GetProcessHeap(), 0, mem_orig); HeapFree(GetProcessHeap(), 0, StubMsg.BufferStart); }
@@ -381,15 +406,15 @@ static void test_simple_types(void) 0x2, /* FC_CHAR */ 0x5c, /* FC_PAD */ }; - static const unsigned char fmtstr_rpup_char[] = + static const unsigned char fmtstr_rpup_char_onstack_deref[] = { - 0x11, 0x14, /* FC_RP [alloced_on_stack] */ + 0x11, 0x14, /* FC_RP [alloced_on_stack] [pointer_deref] */ NdrFcShort( 0x2 ), /* Offset= 2 (4) */ 0x12, 0x8, /* FC_UP [simple_pointer] */ 0x2, /* FC_CHAR */ 0x5c, /* FC_PAD */ }; - static const unsigned char fmtstr_rpup_char2[] = + static const unsigned char fmtstr_rpup_char_onstack[] = { 0x11, 0x04, /* FC_RP [alloced_on_stack] */ NdrFcShort( 0x2 ), /* Offset= 2 (4) */ @@ -397,6 +422,14 @@ static void test_simple_types(void) 0x2, /* FC_CHAR */ 0x5c, /* FC_PAD */ }; + static const unsigned char fmtstr_rpup_char_deref[] = + { + 0x11, 0x10, /* FC_RP [pointer_deref] */ + NdrFcShort( 0x2 ), /* Offset= 2 (4) */ + 0x12, 0x8, /* FC_UP [simple_pointer] */ + 0x2, /* FC_CHAR */ + 0x5c, /* FC_PAD */ + };
static const unsigned char fmtstr_up_wchar[] = { @@ -481,8 +514,9 @@ static void test_simple_types(void)
test_pointer_marshal(fmtstr_rp_char, ch_ptr, 1, &ch, 1, NULL, 0, "rp_char");
- test_pointer_marshal(fmtstr_rpup_char, &ch_ptr, 1, wiredata, 5, deref_cmp, 1, "rpup_char"); - test_pointer_marshal(fmtstr_rpup_char2, ch_ptr, 1, wiredata, 5, NULL, 0, "rpup_char2"); + test_pointer_marshal(fmtstr_rpup_char_onstack_deref, &ch_ptr, 1, wiredata, 5, deref_cmp, 1, "rpup_char_onstack_deref"); + test_pointer_marshal(fmtstr_rpup_char_onstack, ch_ptr, 1, wiredata, 5, NULL, 0, "rpup_char_onstack"); + test_pointer_marshal(fmtstr_rpup_char_deref, &ch_ptr, 1, wiredata, 5, deref_cmp, 1, "rpup_char_deref");
s = 0xa597; if (use_pointer_ids)
Signed-off-by: Huw Davies huw@codeweavers.com
Signed-off-by: Zebediah Figura z.figura12@gmail.com --- dlls/rpcrt4/tests/ndr_marshall.c | 151 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 151 insertions(+)
diff --git a/dlls/rpcrt4/tests/ndr_marshall.c b/dlls/rpcrt4/tests/ndr_marshall.c index 2938b87..e4231ae 100644 --- a/dlls/rpcrt4/tests/ndr_marshall.c +++ b/dlls/rpcrt4/tests/ndr_marshall.c @@ -355,6 +355,157 @@ todo_wine { } } } + + /* Server */ + StubMsg.IsClient = 0; + + /* For most basetypes (but not enum16), memory will not be allocated but + * instead point directly to the buffer. */ + my_alloc_called = my_free_called = 0; + StubMsg.Buffer = StubMsg.BufferStart; + mem = NULL; + ptr = NdrPointerUnmarshall( &StubMsg, &mem, formattypes, 0 ); + ok(ptr == NULL, "%s: ret %p\n", msgpfx, ptr); + ok(!!mem, "%s: mem was not allocated\n", msgpfx); + ok(!cmp(mem, memsrc, srcsize), "%s: incorrectly unmarshaled\n", msgpfx); + ok(StubMsg.Buffer - StubMsg.BufferStart == wiredatalen, "%s: Buffer %p Start %p len %d\n", msgpfx, StubMsg.Buffer, StubMsg.BufferStart, wiredatalen); + ok(StubMsg.MemorySize == 0, "%s: memorysize %d\n", msgpfx, StubMsg.MemorySize); + if (formattypes[2] == FC_ENUM16) + ok(my_alloc_called == 1, "%s: my_alloc got called %d times\n", msgpfx, my_alloc_called); + else +todo_wine_if(formattypes[1] & FC_POINTER_DEREF) + ok(my_alloc_called == num_additional_allocs, "%s: my_alloc got called %d times\n", msgpfx, my_alloc_called); + ok(!my_free_called, "%s: my_free got called %d times\n", msgpfx, my_free_called); + + NdrPointerFree(&StubMsg, mem, formattypes); + if (formattypes[2] == FC_ENUM16) + ok(my_free_called == 1, "%s: my_free got called %d times\n", msgpfx, my_free_called); + else if ((formattypes[1] & FC_ALLOCED_ON_STACK) && (formattypes[1] & FC_POINTER_DEREF)) + { + /* In theory this should be freed to correspond with the allocation, but + * FC_ALLOCED_ON_STACK is set, and NdrPointerFree() has no way of + * knowing that the memory allocated by NdrPointerUnmarshall() isn't + * stack memory. In practice it always *is* stack memory if ON_STACK is + * set, so this leak isn't a concern. */ +todo_wine + ok(my_free_called == 0, "%s: my_free got called %d times\n", msgpfx, my_free_called); + HeapFree(GetProcessHeap(), 0, mem); + } + else +todo_wine_if((formattypes[1] & FC_POINTER_DEREF) && !(formattypes[1] & FC_ALLOCED_ON_STACK)) + ok(my_free_called == num_additional_allocs, "%s: my_free got called %d times\n", msgpfx, my_free_called); + + /* reset the buffer and call with must alloc */ + my_alloc_called = my_free_called = 0; + StubMsg.Buffer = StubMsg.BufferStart; + mem = NULL; + ptr = NdrPointerUnmarshall( &StubMsg, &mem, formattypes, 1 ); + ok(ptr == NULL, "%s: ret %p\n", msgpfx, ptr); + ok(!!mem, "%s: mem was not allocated\n", msgpfx); + ok(!cmp(mem, memsrc, srcsize), "%s: incorrectly unmarshaled\n", msgpfx); + ok(StubMsg.Buffer - StubMsg.BufferStart == wiredatalen, "%s: Buffer %p Start %p len %d\n", msgpfx, StubMsg.Buffer, StubMsg.BufferStart, wiredatalen); + ok(StubMsg.MemorySize == 0, "%s: memorysize %d\n", msgpfx, StubMsg.MemorySize); + if (formattypes[2] == FC_ENUM16) + ok(my_alloc_called == 1, "%s: my_alloc got called %d times\n", msgpfx, my_alloc_called); + else +todo_wine + ok(my_alloc_called == num_additional_allocs, "%s: my_alloc got called %d times\n", msgpfx, my_alloc_called); + ok(!my_free_called, "%s: my_free got called %d times\n", msgpfx, my_free_called); + + NdrPointerFree(&StubMsg, mem, formattypes); + if (formattypes[2] == FC_ENUM16) + ok(my_free_called == 1, "%s: my_free got called %d times\n", msgpfx, my_free_called); + else if ((formattypes[1] & FC_ALLOCED_ON_STACK) && (formattypes[1] & FC_POINTER_DEREF)) + { +todo_wine + ok(my_free_called == 0, "%s: my_free got called %d times\n", msgpfx, my_free_called); + HeapFree(GetProcessHeap(), 0, mem); + } + else +todo_wine + ok(my_free_called == num_additional_allocs, "%s: my_free got called %d times\n", msgpfx, my_free_called); + + /* Ξ€est with an existing pointer. Unless it's a stack pointer (and deref'd) + * a new pointer will be allocated anyway (in fact, an invalid pointer works + * in every such case). */ + + my_alloc_called = my_free_called = 0; + StubMsg.Buffer = StubMsg.BufferStart; + mem_orig = mem = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, size); + if (formattypes[1] & FC_POINTER_DEREF) + *(void**)mem = NULL; + ptr = NdrPointerUnmarshall( &StubMsg, &mem, formattypes, 0 ); + ok(ptr == NULL, "%s: ret %p\n", msgpfx, ptr); + if ((formattypes[1] & FC_ALLOCED_ON_STACK) && (formattypes[1] & FC_POINTER_DEREF)) +todo_wine + ok(mem == mem_orig, "%s: mem has changed %p %p\n", msgpfx, mem, mem_orig); + else + ok(mem != mem_orig, "%s: mem has not changed\n", msgpfx); + ok(!cmp(mem, memsrc, srcsize), "%s: incorrectly unmarshaled\n", msgpfx); + ok(StubMsg.Buffer - StubMsg.BufferStart == wiredatalen, "%s: Buffer %p Start %p len %d\n", msgpfx, StubMsg.Buffer, StubMsg.BufferStart, wiredatalen); + ok(StubMsg.MemorySize == 0, "%s: memorysize %d\n", msgpfx, StubMsg.MemorySize); + if (formattypes[2] == FC_ENUM16) + ok(my_alloc_called == 1, "%s: my_alloc got called %d times\n", msgpfx, my_alloc_called); + else if ((formattypes[1] & FC_ALLOCED_ON_STACK) && (formattypes[1] & FC_POINTER_DEREF)) +todo_wine + ok(my_alloc_called == 0, "%s: my_alloc got called %d times\n", msgpfx, my_free_called); + else +todo_wine_if(formattypes[1] & FC_POINTER_DEREF) + ok(my_alloc_called == num_additional_allocs, "%s: my_alloc got called %d times\n", msgpfx, my_alloc_called); + ok(!my_free_called, "%s: my_free got called %d times\n", msgpfx, my_free_called); + + NdrPointerFree(&StubMsg, mem, formattypes); + if (formattypes[2] == FC_ENUM16) + ok(my_free_called == 1, "%s: my_free got called %d times\n", msgpfx, my_free_called); + else if ((formattypes[1] & FC_ALLOCED_ON_STACK) && (formattypes[1] & FC_POINTER_DEREF)) + { +todo_wine + ok(my_free_called == 0, "%s: my_free got called %d times\n", msgpfx, my_free_called); + HeapFree(GetProcessHeap(), 0, mem); + } + else +todo_wine_if((formattypes[1] & FC_POINTER_DEREF) && !(formattypes[1] & FC_ALLOCED_ON_STACK)) + ok(my_free_called == num_additional_allocs, "%s: my_free got called %d times\n", msgpfx, my_free_called); + + /* reset the buffer and call with must alloc */ + my_alloc_called = my_free_called = 0; + StubMsg.Buffer = StubMsg.BufferStart; + mem_orig = mem = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, size); + if (formattypes[1] & FC_POINTER_DEREF) + *(void**)mem = NULL; + ptr = NdrPointerUnmarshall( &StubMsg, &mem, formattypes, 1 ); + ok(ptr == NULL, "%s: ret %p\n", msgpfx, ptr); + if ((formattypes[1] & FC_ALLOCED_ON_STACK) && (formattypes[1] & FC_POINTER_DEREF)) +todo_wine + ok(mem == mem_orig, "%s: mem has changed %p %p\n", msgpfx, mem, mem_orig); + else + ok(mem != mem_orig, "%s: mem has not changed\n", msgpfx); + ok(!cmp(mem, memsrc, srcsize), "%s: incorrectly unmarshaled\n", msgpfx); + ok(StubMsg.Buffer - StubMsg.BufferStart == wiredatalen, "%s: Buffer %p Start %p len %d\n", msgpfx, StubMsg.Buffer, StubMsg.BufferStart, wiredatalen); + ok(StubMsg.MemorySize == 0, "%s: memorysize %d\n", msgpfx, StubMsg.MemorySize); + if (formattypes[2] == FC_ENUM16) + ok(my_alloc_called == 1, "%s: my_alloc got called %d times\n", msgpfx, my_alloc_called); + else if ((formattypes[1] & FC_ALLOCED_ON_STACK) && (formattypes[1] & FC_POINTER_DEREF)) +todo_wine + ok(my_alloc_called == 0, "%s: my_alloc got called %d times\n", msgpfx, my_free_called); + else +todo_wine + ok(my_alloc_called == num_additional_allocs, "%s: my_alloc got called %d times\n", msgpfx, my_alloc_called); + ok(!my_free_called, "%s: my_free got called %d times\n", msgpfx, my_free_called); + + NdrPointerFree(&StubMsg, mem, formattypes); + if (formattypes[2] == FC_ENUM16) + ok(my_free_called == 1, "%s: my_free got called %d times\n", msgpfx, my_free_called); + else if ((formattypes[1] & FC_ALLOCED_ON_STACK) && (formattypes[1] & FC_POINTER_DEREF)) + { +todo_wine + ok(my_free_called == 0, "%s: my_free got called %d times\n", msgpfx, my_free_called); + HeapFree(GetProcessHeap(), 0, mem); + } + else +todo_wine + ok(my_free_called == num_additional_allocs, "%s: my_free got called %d times\n", msgpfx, my_free_called); + HeapFree(GetProcessHeap(), 0, StubMsg.BufferStart); }
Signed-off-by: Huw Davies huw@codeweavers.com
Signed-off-by: Zebediah Figura z.figura12@gmail.com --- dlls/rpcrt4/ndr_marshall.c | 5 ++++- dlls/rpcrt4/tests/ndr_marshall.c | 8 +++----- 2 files changed, 7 insertions(+), 6 deletions(-)
diff --git a/dlls/rpcrt4/ndr_marshall.c b/dlls/rpcrt4/ndr_marshall.c index 58f0108..b48b300 100644 --- a/dlls/rpcrt4/ndr_marshall.c +++ b/dlls/rpcrt4/ndr_marshall.c @@ -944,7 +944,10 @@ static void PointerUnmarshall(PMIDL_STUB_MESSAGE pStubMsg, * setting the pointer to the buffer, if possible, or set fMustAlloc to * TRUE. */ if (attr & FC_POINTER_DEREF) { - fMustAlloc = TRUE; + if (pSrcPointer && (attr & FC_ALLOCED_ON_STACK)) + *pPointer = pSrcPointer; + else + fMustAlloc = TRUE; } else { *current_ptr = NULL; } diff --git a/dlls/rpcrt4/tests/ndr_marshall.c b/dlls/rpcrt4/tests/ndr_marshall.c index e4231ae..2695d46 100644 --- a/dlls/rpcrt4/tests/ndr_marshall.c +++ b/dlls/rpcrt4/tests/ndr_marshall.c @@ -437,7 +437,6 @@ todo_wine ptr = NdrPointerUnmarshall( &StubMsg, &mem, formattypes, 0 ); ok(ptr == NULL, "%s: ret %p\n", msgpfx, ptr); if ((formattypes[1] & FC_ALLOCED_ON_STACK) && (formattypes[1] & FC_POINTER_DEREF)) -todo_wine ok(mem == mem_orig, "%s: mem has changed %p %p\n", msgpfx, mem, mem_orig); else ok(mem != mem_orig, "%s: mem has not changed\n", msgpfx); @@ -849,10 +848,9 @@ static void test_nontrivial_pointer_types(void) *(void **)mem = NULL; StubMsg.Buffer = StubMsg.BufferStart; NdrPointerUnmarshall( &StubMsg, &mem, &fmtstr_ref_unique_out[4], 0); - todo_wine { - ok(mem == mem_orig, "mem alloced\n"); - ok(my_alloc_called == 0, "alloc called %d\n", my_alloc_called); - } + ok(mem == mem_orig, "mem alloced\n"); +todo_wine + ok(my_alloc_called == 0, "alloc called %d\n", my_alloc_called);
my_alloc_called = 0; mem = mem_orig;
Signed-off-by: Huw Davies huw@codeweavers.com