Memory Issues in RPC
Hi Guys,
I am creating a client server program using RPC.
I have Server API in IDL as:
IDL:
HRESULT GetBlob([out] DWORD *pdwBlobByteCount,[out,
size_is(,*pdwBlobByteCount)] BYTE** ppBlob);
This function returns an array of byte and byte count as output
params.
Now as required by RPC I need to implement memory functions on both
client and server.
midl_user_allocate(..)
midl_user_free(..)
Lets look at client code:
{
....
DWORD dwCoun=0;
BYTE *pBlob=NULL;
HRESULT hr = GetBlob(&dwcount,&pBlob);
....
....
// after using pBlob
if(pBlob!=NULL)
midl_user_free(pBlob);
}
Server Code:
HRESULT GetBlob(__out DWORD *pdwBlobByteCount,__out BYTE** ppBlob){
.....
DWORD count=10;
BYTE *pByte = (BYTE*)mild_user_allocate(sizeof(BYTE)*10);
if(pByte!=NULL){
*pdwBlobByteCount = count;
*ppBlob = pByte;
}
....
}
Issue:
RPC
Server<<--Stub-->> ----------------------------------------<<Stub--
Now Server allocate Byte array and send that array to server stub.
Server stub marshals that array and passes over RPC to client, also
server stub deallocates the memory allocated by server.
client stub marshals the data passed by server stub, allocates memory
in client and passes that data to client.
When client is done with that data , it needs to call
midl_user_free()...
Now my question is how the client will know how much memory to
deallocate when midl_user_free() if called.
wheneneve I do midl_user_free() , I am getting DEBUGCHK failed in
rheap.cpp
Any suggestions, Am i doing something wrong here????