[PATCH 5/5] Remove S_OK value assumptions, fix potential stream leak
Nikolay Sivov
nsivov at codeweavers.com
Tue Jan 18 15:52:44 CST 2011
---
dlls/oleaut32/tmarshal.c | 111 ++++++++++++++++++++++++---------------------
1 files changed, 59 insertions(+), 52 deletions(-)
diff --git a/dlls/oleaut32/tmarshal.c b/dlls/oleaut32/tmarshal.c
index 9d3d73e..31f5284 100644
--- a/dlls/oleaut32/tmarshal.c
+++ b/dlls/oleaut32/tmarshal.c
@@ -137,7 +137,7 @@ _unmarshal_interface(marshal_state *buf, REFIID riid, LPUNKNOWN *pUnk) {
*pUnk = NULL;
hres = xbuf_get(buf,(LPBYTE)&xsize,sizeof(xsize));
- if (hres) {
+ if (hres != S_OK) {
ERR("xbuf_get failed\n");
return hres;
}
@@ -145,27 +145,30 @@ _unmarshal_interface(marshal_state *buf, REFIID riid, LPUNKNOWN *pUnk) {
if (xsize == 0) return S_OK;
hres = CreateStreamOnHGlobal(0,TRUE,&pStm);
- if (hres) {
- ERR("Stream create failed %x\n",hres);
+ if (hres != S_OK) {
+ ERR("Stream create failed 0x%08x\n", hres);
return hres;
}
hres = IStream_Write(pStm,buf->base+buf->curoff,xsize,&res);
- if (hres) {
- ERR("stream write %x\n",hres);
+ if (hres != S_OK) {
+ ERR("stream write 0x%08x\n", hres);
+ IStream_Release(pStm);
return hres;
}
memset(&seekto,0,sizeof(seekto));
hres = IStream_Seek(pStm,seekto,SEEK_SET,&newpos);
- if (hres) {
- ERR("Failed Seek %x\n",hres);
+ if (hres != S_OK) {
+ ERR("Failed Seek 0x%08x\n", hres);
+ IStream_Release(pStm);
return hres;
}
hres = CoUnmarshalInterface(pStm,riid,(LPVOID*)pUnk);
- if (hres) {
- ERR("Unmarshalling interface %s failed with %x\n",debugstr_guid(riid),hres);
+ if (hres != S_OK) {
+ ERR("Unmarshalling interface %s failed with 0x%08x\n", debugstr_guid(riid), hres);
+ IStream_Release(pStm);
return hres;
}
@@ -200,19 +203,19 @@ _marshal_interface(marshal_state *buf, REFIID riid, LPUNKNOWN pUnk) {
TRACE("...%s...\n",debugstr_guid(riid));
hres = CreateStreamOnHGlobal(0,TRUE,&pStm);
- if (hres) {
+ if (hres != S_OK) {
ERR("Stream create failed %x\n",hres);
goto fail;
}
hres = CoMarshalInterface(pStm,riid,pUnk,0,NULL,0);
- if (hres) {
+ if (hres != S_OK) {
ERR("Marshalling interface %s failed with %x\n", debugstr_guid(riid), hres);
goto fail;
}
hres = IStream_Stat(pStm,&ststg,STATFLAG_NONAME);
- if (hres) {
+ if (hres != S_OK) {
ERR("Stream stat failed\n");
goto fail;
}
@@ -220,13 +223,13 @@ _marshal_interface(marshal_state *buf, REFIID riid, LPUNKNOWN pUnk) {
tempbuf = HeapAlloc(GetProcessHeap(), 0, ststg.cbSize.u.LowPart);
memset(&seekto,0,sizeof(seekto));
hres = IStream_Seek(pStm,seekto,SEEK_SET,&newpos);
- if (hres) {
+ if (hres != S_OK) {
ERR("Failed Seek %x\n",hres);
goto fail;
}
hres = IStream_Read(pStm,tempbuf,ststg.cbSize.u.LowPart,&res);
- if (hres) {
+ if (hres != S_OK) {
ERR("Failed Read %x\n",hres);
goto fail;
}
@@ -305,12 +308,12 @@ _get_typeinfo_for_iid(REFIID riid, ITypeInfo**ti) {
}
MultiByteToWideChar(CP_ACP, 0, tlfn, -1, tlfnW, sizeof(tlfnW) / sizeof(tlfnW[0]));
hres = LoadTypeLib(tlfnW,&tl);
- if (hres) {
+ if (hres != S_OK) {
ERR("Failed to load typelib for %s, but it should be there.\n",debugstr_guid(riid));
return hres;
}
hres = ITypeLib_GetTypeInfoOfGuid(tl,riid,ti);
- if (hres) {
+ if (hres != S_OK) {
ERR("typelib does not contain info for %s?\n",debugstr_guid(riid));
ITypeLib_Release(tl);
return hres;
@@ -331,7 +334,7 @@ static HRESULT num_of_funcs(ITypeInfo *tinfo, unsigned int *num)
*num = 0;
hres = ITypeInfo_GetTypeAttr(tinfo, &attr);
- if (hres) {
+ if (hres != S_OK) {
ERR("GetTypeAttr failed with %x\n",hres);
return hres;
}
@@ -702,7 +705,7 @@ serialize_param(
TYPEATTR *tattr;
hres = ITypeInfo_GetRefTypeInfo(tinfo,tdesc->u.lptdesc->u.hreftype,&tinfo2);
- if (hres) {
+ if (hres != S_OK) {
ERR("Could not get typeinfo of hreftype %x for VT_USERDEFINED.\n",tdesc->u.lptdesc->u.hreftype);
return hres;
}
@@ -715,7 +718,7 @@ serialize_param(
ITypeInfo_ReleaseTypeAttr(tinfo, tattr);
ITypeInfo_Release(tinfo2);
hres = ITypeInfo_GetRefTypeInfo(tinfo,href,&tinfo2);
- if (hres) {
+ if (hres != S_OK) {
ERR("Could not get typeinfo of hreftype %x for VT_USERDEFINED.\n",tdesc->u.lptdesc->u.hreftype);
return hres;
}
@@ -744,7 +747,7 @@ serialize_param(
*/
cookie = *arg ? 0x42424242 : 0;
hres = xbuf_add(buf,(LPBYTE)&cookie,sizeof(cookie));
- if (hres)
+ if (hres != S_OK)
return hres;
if (!*arg) {
if (debugout) TRACE_(olerelay)("NULL");
@@ -776,7 +779,7 @@ serialize_param(
TYPEATTR *tattr;
hres = ITypeInfo_GetRefTypeInfo(tinfo,tdesc->u.hreftype,&tinfo2);
- if (hres) {
+ if (hres != S_OK) {
ERR("Could not get typeinfo of hreftype %x for VT_USERDEFINED.\n",tdesc->u.hreftype);
return hres;
}
@@ -922,7 +925,7 @@ deserialize_param(
case VT_CY:
if (readit) {
hres = xbuf_get(buf,(LPBYTE)arg,8);
- if (hres) ERR("Failed to read integer 8 byte\n");
+ if (hres != S_OK) ERR("Failed to read integer 8 byte\n");
}
if (debugout) TRACE_(olerelay)("%x%x",arg[0],arg[1]);
return hres;
@@ -934,7 +937,7 @@ deserialize_param(
case VT_UI4:
if (readit) {
hres = xbuf_get(buf,(LPBYTE)arg,sizeof(DWORD));
- if (hres) ERR("Failed to read integer 4 byte\n");
+ if (hres != S_OK) ERR("Failed to read integer 4 byte\n");
}
if (debugout) TRACE_(olerelay)("%x",*arg);
return hres;
@@ -944,7 +947,7 @@ deserialize_param(
if (readit) {
DWORD x;
hres = xbuf_get(buf,(LPBYTE)&x,sizeof(DWORD));
- if (hres) ERR("Failed to read integer 4 byte\n");
+ if (hres != S_OK) ERR("Failed to read integer 4 byte\n");
memcpy(arg,&x,2);
}
if (debugout) TRACE_(olerelay)("%04x",*arg & 0xffff);
@@ -954,7 +957,7 @@ deserialize_param(
if (readit) {
DWORD x;
hres = xbuf_get(buf,(LPBYTE)&x,sizeof(DWORD));
- if (hres) ERR("Failed to read integer 4 byte\n");
+ if (hres != S_OK) ERR("Failed to read integer 4 byte\n");
memcpy(arg,&x,1);
}
if (debugout) TRACE_(olerelay)("%02x",*arg & 0xff);
@@ -979,7 +982,7 @@ deserialize_param(
TYPEATTR *tattr;
hres = ITypeInfo_GetRefTypeInfo(tinfo,tdesc->u.lptdesc->u.hreftype,&tinfo2);
- if (hres) {
+ if (hres != S_OK) {
ERR("Could not get typeinfo of hreftype %x for VT_USERDEFINED.\n",tdesc->u.lptdesc->u.hreftype);
return hres;
}
@@ -992,7 +995,7 @@ deserialize_param(
ITypeInfo_ReleaseTypeAttr(tinfo, tattr);
ITypeInfo_Release(tinfo2);
hres = ITypeInfo_GetRefTypeInfo(tinfo,href,&tinfo2);
- if (hres) {
+ if (hres != S_OK) {
ERR("Could not get typeinfo of hreftype %x for VT_USERDEFINED.\n",tdesc->u.lptdesc->u.hreftype);
return hres;
}
@@ -1019,7 +1022,7 @@ deserialize_param(
* NULL pointer or not.
*/
hres = xbuf_get(buf,(LPBYTE)&cookie,sizeof(cookie));
- if (hres) {
+ if (hres != S_OK) {
ERR("Failed to load pointer cookie.\n");
return hres;
}
@@ -1065,12 +1068,12 @@ deserialize_param(
TYPEATTR *tattr;
hres = ITypeInfo_GetRefTypeInfo(tinfo,tdesc->u.hreftype,&tinfo2);
- if (hres) {
+ if (hres != S_OK) {
ERR("Could not get typeinfo of hreftype %x for VT_USERDEFINED.\n",tdesc->u.hreftype);
return hres;
}
hres = ITypeInfo_GetTypeAttr(tinfo2,&tattr);
- if (hres) {
+ if (hres != S_OK) {
ERR("Could not get typeattr in VT_USERDEFINED.\n");
} else {
switch (tattr->typekind) {
@@ -1087,7 +1090,7 @@ deserialize_param(
VARDESC *vdesc;
hres = ITypeInfo2_GetVarDesc(tinfo2, i, &vdesc);
- if (hres) {
+ if (hres != S_OK) {
ERR("Could not get vardesc of %d\n",i);
ITypeInfo_ReleaseTypeAttr(tinfo2, tattr);
ITypeInfo_Release(tinfo2);
@@ -1114,7 +1117,7 @@ deserialize_param(
case TKIND_ENUM:
if (readit) {
hres = xbuf_get(buf,(LPBYTE)arg,sizeof(DWORD));
- if (hres) ERR("Failed to read enum (4 byte)\n");
+ if (hres != S_OK) ERR("Failed to read enum (4 byte)\n");
}
if (debugout) TRACE_(olerelay)("%x",*arg);
break;
@@ -1125,7 +1128,7 @@ deserialize_param(
}
ITypeInfo_ReleaseTypeAttr(tinfo2, tattr);
}
- if (hres)
+ if (hres != S_OK)
ERR("failed to stuballoc in TKIND_RECORD.\n");
ITypeInfo_Release(tinfo2);
return hres;
@@ -1293,7 +1296,7 @@ xCall(LPVOID retptr, int method, TMProxyImpl *tpinfo /*, args */)
EnterCriticalSection(&tpinfo->crit);
hres = get_funcdesc(tpinfo->tinfo,method,&tinfo,&fdesc,&iname,&fname,NULL);
- if (hres) {
+ if (hres != S_OK) {
ERR("Did not find typeinfo/funcdesc entry for method %d!\n",method);
LeaveCriticalSection(&tpinfo->crit);
return E_FAIL;
@@ -1360,7 +1363,7 @@ xCall(LPVOID retptr, int method, TMProxyImpl *tpinfo /*, args */)
&buf
);
- if (hres) {
+ if (hres != S_OK) {
ERR("Failed to serialize param, hres %x\n",hres);
break;
}
@@ -1372,14 +1375,14 @@ xCall(LPVOID retptr, int method, TMProxyImpl *tpinfo /*, args */)
msg.cbBuffer = buf.curoff;
msg.iMethod = method;
hres = IRpcChannelBuffer_GetBuffer(chanbuf,&msg,&(tpinfo->iid));
- if (hres) {
+ if (hres != S_OK) {
ERR("RpcChannelBuffer GetBuffer failed, %x\n",hres);
goto exit;
}
memcpy(msg.Buffer,buf.base,buf.curoff);
if (relaydeb) TRACE_(olerelay)("\n");
hres = IRpcChannelBuffer_SendReceive(chanbuf,&msg,&status);
- if (hres) {
+ if (hres != S_OK) {
ERR("RpcChannelBuffer SendReceive failed, %x\n",hres);
goto exit;
}
@@ -1418,7 +1421,7 @@ xCall(LPVOID retptr, int method, TMProxyImpl *tpinfo /*, args */)
xargs,
&buf
);
- if (hres) {
+ if (hres != S_OK) {
ERR("Failed to unmarshall param, hres %x\n",hres);
status = hres;
break;
@@ -1562,12 +1565,13 @@ static ULONG WINAPI TMarshalDispatchChannel_Release(LPRPCCHANNELBUFFER iface)
ULONG ref;
ref = InterlockedDecrement(&This->refs);
- if (ref)
- return ref;
+ if (!ref)
+ {
+ IRpcChannelBuffer_Release(This->pDelegateChannel);
+ HeapFree(GetProcessHeap(), 0, This);
+ }
- IRpcChannelBuffer_Release(This->pDelegateChannel);
- HeapFree(GetProcessHeap(), 0, This);
- return 0;
+ return ref;
}
static HRESULT WINAPI TMarshalDispatchChannel_GetBuffer(LPRPCCHANNELBUFFER iface, RPCOLEMESSAGE* olemsg, REFIID riid)
@@ -1644,7 +1648,7 @@ static inline HRESULT get_facbuf_for_iid(REFIID riid, IPSFactoryBuffer **facbuf)
HRESULT hr;
CLSID clsid;
- if ((hr = CoGetPSClsid(riid, &clsid)))
+ if ((hr = CoGetPSClsid(riid, &clsid)) != S_OK)
return hr;
return CoGetClassObject(&clsid, CLSCTX_INPROC_SERVER, NULL,
&IID_IPSFactoryBuffer, (LPVOID*)facbuf);
@@ -1661,7 +1665,7 @@ static HRESULT init_proxy_entry_point(TMProxyImpl *proxy, unsigned int num)
const FUNCDESC *fdesc;
hres = get_funcdesc(proxy->tinfo, num, &tinfo2, &fdesc, NULL, NULL, NULL);
- if (hres) {
+ if (hres != S_OK) {
ERR("GetFuncDesc %x should not fail here.\n",hres);
return hres;
}
@@ -1717,7 +1721,7 @@ PSFacBuf_CreateProxy(
TRACE("(...%s...)\n",debugstr_guid(riid));
hres = _get_typeinfo_for_iid(riid,&tinfo);
- if (hres) {
+ if (hres != S_OK) {
ERR("No typeinfo for %s?\n",debugstr_guid(riid));
return hres;
}
@@ -1980,7 +1984,7 @@ TMStubImpl_Invoke(
buf.curoff = 0;
hres = get_funcdesc(This->tinfo,xmsg->iMethod,&tinfo,&fdesc,&iname,NULL,NULL);
- if (hres) {
+ if (hres != S_OK) {
ERR("GetFuncDesc on method %d failed with %x\n",xmsg->iMethod,hres);
return hres;
}
@@ -2028,7 +2032,7 @@ TMStubImpl_Invoke(
&buf
);
xargs += _argsize(&elem->tdesc, tinfo);
- if (hres) {
+ if (hres != S_OK) {
ERR("Failed to deserialize param %s, hres %x\n",relaystr(names[i+1]),hres);
break;
}
@@ -2074,7 +2078,7 @@ TMStubImpl_Invoke(
&buf
);
xargs += _argsize(&elem->tdesc, tinfo);
- if (hres) {
+ if (hres != S_OK) {
ERR("Failed to stuballoc param, hres %x\n",hres);
break;
}
@@ -2160,14 +2164,17 @@ PSFacBuf_CreateStub(
TRACE("(%s,%p,%p)\n",debugstr_guid(riid),pUnkServer,ppStub);
hres = _get_typeinfo_for_iid(riid,&tinfo);
- if (hres) {
+ if (hres != S_OK) {
ERR("No typeinfo for %s?\n",debugstr_guid(riid));
return hres;
}
stub = CoTaskMemAlloc(sizeof(TMStubImpl));
- if (!stub)
+ if (!stub) {
+ ITypeInfo_Release(tinfo);
return E_OUTOFMEMORY;
+ }
+
stub->IRpcStubBuffer_iface.lpVtbl = &tmstubvtbl;
stub->ref = 1;
stub->tinfo = tinfo;
@@ -2177,7 +2184,7 @@ PSFacBuf_CreateStub(
hres = IRpcStubBuffer_Connect(&stub->IRpcStubBuffer_iface,pUnkServer);
*ppStub = &stub->IRpcStubBuffer_iface;
TRACE("IRpcStubBuffer: %p\n", stub);
- if (hres)
+ if (hres != S_OK)
ERR("Connect to pUnkServer failed?\n");
/* if we derive from IDispatch then defer to its stub for some of its methods */
--
1.5.6.5
--------------010407020706010509040101--
More information about the wine-patches
mailing list