Commit e8d89cd0 authored by Huw Davies's avatar Huw Davies Committed by Alexandre Julliard

Fix a reference leak on failure (spotted by Rob Shearman).

Move some code over to the Interlocked* functions.
parent 076b5b70
......@@ -95,15 +95,17 @@ AMCF_QueryInterface(LPCLASSFACTORY iface,REFIID riid,LPVOID *ppobj)
return E_NOINTERFACE;
}
static ULONG WINAPI AMCF_AddRef(LPCLASSFACTORY iface) {
static ULONG WINAPI AMCF_AddRef(LPCLASSFACTORY iface)
{
IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
return ++(This->ref);
return InterlockedIncrement(&This->ref);
}
static ULONG WINAPI AMCF_Release(LPCLASSFACTORY iface) {
static ULONG WINAPI AMCF_Release(LPCLASSFACTORY iface)
{
IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
ULONG ref = --This->ref;
ULONG ref = InterlockedDecrement(&This->ref);
if (ref == 0)
HeapFree(GetProcessHeap(), 0, This);
......@@ -113,28 +115,26 @@ static ULONG WINAPI AMCF_Release(LPCLASSFACTORY iface) {
static HRESULT WINAPI AMCF_CreateInstance(LPCLASSFACTORY iface, LPUNKNOWN pOuter,
REFIID riid, LPVOID *ppobj) {
REFIID riid, LPVOID *ppobj)
{
IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
HRESULT hres;
LPUNKNOWN punk;
TRACE("(%p)->(%p,%s,%p)\n",This,pOuter,debugstr_guid(riid),ppobj);
*ppobj = NULL;
hres = This->pfnCreateInstance(pOuter, (LPVOID *) &punk);
if (FAILED(hres)) {
*ppobj = NULL;
return hres;
}
hres = IUnknown_QueryInterface(punk, riid, ppobj);
if (FAILED(hres)) {
*ppobj = NULL;
return hres;
if (SUCCEEDED(hres)) {
hres = IUnknown_QueryInterface(punk, riid, ppobj);
IUnknown_Release(punk);
}
IUnknown_Release(punk);
return hres;
}
static HRESULT WINAPI AMCF_LockServer(LPCLASSFACTORY iface,BOOL dolock) {
static HRESULT WINAPI AMCF_LockServer(LPCLASSFACTORY iface,BOOL dolock)
{
IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
FIXME("(%p)->(%d),stub!\n",This,dolock);
return S_OK;
......
......@@ -97,14 +97,14 @@ static HRESULT WINAPI XFCF_QueryInterface(LPCLASSFACTORY iface,REFIID riid, LPVO
static ULONG WINAPI XFCF_AddRef(LPCLASSFACTORY iface)
{
IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
return ++(This->ref);
return InterlockedIncrement(&This->ref);
}
static ULONG WINAPI XFCF_Release(LPCLASSFACTORY iface)
{
IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
ULONG ref = --This->ref;
ULONG ref = InterlockedDecrement(&This->ref);
if (ref == 0)
HeapFree(GetProcessHeap(), 0, This);
......@@ -120,17 +120,12 @@ static HRESULT WINAPI XFCF_CreateInstance(LPCLASSFACTORY iface, LPUNKNOWN pOuter
TRACE("(%p)->(%p,%s,%p)\n",This,pOuter,debugstr_guid(riid),ppobj);
*ppobj = NULL;
hres = This->pfnCreateInstance(pOuter, (LPVOID *) &punk);
if (FAILED(hres)) {
*ppobj = NULL;
return hres;
if (SUCCEEDED(hres)) {
hres = IUnknown_QueryInterface(punk, riid, ppobj);
IUnknown_Release(punk);
}
hres = IUnknown_QueryInterface(punk, riid, ppobj);
if (FAILED(hres)) {
*ppobj = NULL;
return hres;
}
IUnknown_Release(punk);
return hres;
}
......
......@@ -491,29 +491,32 @@ DDCF_QueryInterface(LPCLASSFACTORY iface,REFIID riid,LPVOID *ppobj)
return E_NOINTERFACE;
}
static ULONG WINAPI DDCF_AddRef(LPCLASSFACTORY iface) {
static ULONG WINAPI DDCF_AddRef(LPCLASSFACTORY iface)
{
IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
TRACE("(%p)->() incrementing from %ld.\n", This, This->ref);
return ++(This->ref);
return InterlockedIncrement(&This->ref);
}
static ULONG WINAPI DDCF_Release(LPCLASSFACTORY iface) {
static ULONG WINAPI DDCF_Release(LPCLASSFACTORY iface)
{
IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
ULONG ref = InterlockedDecrement(&This->ref);
TRACE("(%p)->() decrementing from %ld.\n", This, ref+1);
TRACE("(%p)->() decrementing from %ld.\n", This, This->ref);
if (--This->ref == 0)
if (ref == 0)
HeapFree(GetProcessHeap(), 0, This);
return This->ref;
return ref;
}
static HRESULT WINAPI DDCF_CreateInstance(
LPCLASSFACTORY iface,LPUNKNOWN pOuter,REFIID riid,LPVOID *ppobj
) {
)
{
IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
TRACE("(%p)->(%p,%s,%p)\n",This,pOuter,debugstr_guid(riid),ppobj);
......@@ -521,7 +524,8 @@ static HRESULT WINAPI DDCF_CreateInstance(
return This->pfnCreateInstance(pOuter, riid, ppobj);
}
static HRESULT WINAPI DDCF_LockServer(LPCLASSFACTORY iface,BOOL dolock) {
static HRESULT WINAPI DDCF_LockServer(LPCLASSFACTORY iface,BOOL dolock)
{
IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
FIXME("(%p)->(%d),stub!\n",This,dolock);
return S_OK;
......
......@@ -80,13 +80,13 @@ static HRESULT WINAPI DICF_QueryInterface(LPCLASSFACTORY iface,REFIID riid,LPVOI
static ULONG WINAPI DICF_AddRef(LPCLASSFACTORY iface) {
IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
return ++(This->ref);
return InterlockedIncrement(&This->ref);
}
static ULONG WINAPI DICF_Release(LPCLASSFACTORY iface) {
IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
/* static class, won't be freed */
return --(This->ref);
return InterlockedDecrement(&This->ref);
}
static HRESULT WINAPI DICF_CreateInstance(LPCLASSFACTORY iface,LPUNKNOWN pOuter,REFIID riid,LPVOID *ppobj) {
......
......@@ -55,13 +55,13 @@ static HRESULT WINAPI DXDiagCF_QueryInterface(LPCLASSFACTORY iface,REFIID riid,L
static ULONG WINAPI DXDiagCF_AddRef(LPCLASSFACTORY iface) {
IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
return ++(This->ref);
return InterlockedIncrement(&This->ref);
}
static ULONG WINAPI DXDiagCF_Release(LPCLASSFACTORY iface) {
IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
/* static class, won't be freed */
return --(This->ref);
return InterlockedDecrement(&This->ref);
}
static HRESULT WINAPI DXDiagCF_CreateInstance(LPCLASSFACTORY iface,LPUNKNOWN pOuter,REFIID riid,LPVOID *ppobj) {
......
......@@ -103,15 +103,17 @@ ITSSCF_QueryInterface(LPCLASSFACTORY iface,REFIID riid,LPVOID *ppobj)
return E_NOINTERFACE;
}
static ULONG WINAPI ITSSCF_AddRef(LPCLASSFACTORY iface) {
static ULONG WINAPI ITSSCF_AddRef(LPCLASSFACTORY iface)
{
IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
return ++(This->ref);
return InterlockedIncrement(&This->ref);
}
static ULONG WINAPI ITSSCF_Release(LPCLASSFACTORY iface) {
static ULONG WINAPI ITSSCF_Release(LPCLASSFACTORY iface)
{
IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
ULONG ref = --This->ref;
ULONG ref = InterlockedDecrement(&This->ref);
if (ref == 0)
HeapFree(GetProcessHeap(), 0, This);
......@@ -121,28 +123,25 @@ static ULONG WINAPI ITSSCF_Release(LPCLASSFACTORY iface) {
static HRESULT WINAPI ITSSCF_CreateInstance(LPCLASSFACTORY iface, LPUNKNOWN pOuter,
REFIID riid, LPVOID *ppobj) {
REFIID riid, LPVOID *ppobj)
{
IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
HRESULT hres;
LPUNKNOWN punk;
TRACE("(%p)->(%p,%s,%p)\n",This,pOuter,debugstr_guid(riid),ppobj);
*ppobj = NULL;
hres = This->pfnCreateInstance(pOuter, (LPVOID *) &punk);
if (FAILED(hres)) {
*ppobj = NULL;
return hres;
}
hres = IUnknown_QueryInterface(punk, riid, ppobj);
if (FAILED(hres)) {
*ppobj = NULL;
return hres;
if (SUCCEEDED(hres)) {
hres = IUnknown_QueryInterface(punk, riid, ppobj);
IUnknown_Release(punk);
}
IUnknown_Release(punk);
return hres;
}
static HRESULT WINAPI ITSSCF_LockServer(LPCLASSFACTORY iface,BOOL dolock) {
static HRESULT WINAPI ITSSCF_LockServer(LPCLASSFACTORY iface,BOOL dolock)
{
IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
FIXME("(%p)->(%d),stub!\n",This,dolock);
return S_OK;
......
......@@ -681,12 +681,14 @@ MLANGCF_QueryInterface(LPCLASSFACTORY iface,REFIID riid,LPVOID *ppobj)
return E_NOINTERFACE;
}
static ULONG WINAPI MLANGCF_AddRef(LPCLASSFACTORY iface) {
static ULONG WINAPI MLANGCF_AddRef(LPCLASSFACTORY iface)
{
IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
return InterlockedIncrement(&This->ref);
}
static ULONG WINAPI MLANGCF_Release(LPCLASSFACTORY iface) {
static ULONG WINAPI MLANGCF_Release(LPCLASSFACTORY iface)
{
IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
ULONG ref = InterlockedDecrement(&This->ref);
......@@ -701,29 +703,26 @@ static ULONG WINAPI MLANGCF_Release(LPCLASSFACTORY iface) {
}
static HRESULT WINAPI MLANGCF_CreateInstance(LPCLASSFACTORY iface, LPUNKNOWN pOuter,
REFIID riid, LPVOID *ppobj) {
REFIID riid, LPVOID *ppobj)
{
IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
HRESULT hres;
LPUNKNOWN punk;
TRACE("(%p)->(%p,%s,%p)\n",This,pOuter,debugstr_guid(riid),ppobj);
*ppobj = NULL;
hres = This->pfnCreateInstance(pOuter, (LPVOID *) &punk);
if (FAILED(hres)) {
*ppobj = NULL;
return hres;
if (SUCCEEDED(hres)) {
hres = IUnknown_QueryInterface(punk, riid, ppobj);
IUnknown_Release(punk);
}
hres = IUnknown_QueryInterface(punk, riid, ppobj);
if (FAILED(hres)) {
*ppobj = NULL;
return hres;
}
IUnknown_Release(punk);
TRACE("returning (%p) -> %lx\n", *ppobj, hres);
return hres;
}
static HRESULT WINAPI MLANGCF_LockServer(LPCLASSFACTORY iface,BOOL dolock) {
static HRESULT WINAPI MLANGCF_LockServer(LPCLASSFACTORY iface,BOOL dolock)
{
IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
FIXME("(%p)->(%d),stub!\n",This,dolock);
return S_OK;
......
......@@ -89,15 +89,17 @@ DSCF_QueryInterface(LPCLASSFACTORY iface,REFIID riid,LPVOID *ppobj)
return E_NOINTERFACE;
}
static ULONG WINAPI DSCF_AddRef(LPCLASSFACTORY iface) {
static ULONG WINAPI DSCF_AddRef(LPCLASSFACTORY iface)
{
IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
return ++(This->ref);
return InterlockedIncrement(&This->ref);
}
static ULONG WINAPI DSCF_Release(LPCLASSFACTORY iface) {
static ULONG WINAPI DSCF_Release(LPCLASSFACTORY iface)
{
IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
ULONG ref = --This->ref;
ULONG ref = InterlockedDecrement(&This->ref);
if (ref == 0)
HeapFree(GetProcessHeap(), 0, This);
......@@ -107,28 +109,25 @@ static ULONG WINAPI DSCF_Release(LPCLASSFACTORY iface) {
static HRESULT WINAPI DSCF_CreateInstance(LPCLASSFACTORY iface, LPUNKNOWN pOuter,
REFIID riid, LPVOID *ppobj) {
REFIID riid, LPVOID *ppobj)
{
IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
HRESULT hres;
LPUNKNOWN punk;
TRACE("(%p)->(%p,%s,%p)\n",This,pOuter,debugstr_guid(riid),ppobj);
*ppobj = NULL;
hres = This->pfnCreateInstance(pOuter, (LPVOID *) &punk);
if (FAILED(hres)) {
*ppobj = NULL;
return hres;
if (SUCCEEDED(hres)) {
hres = IUnknown_QueryInterface(punk, riid, ppobj);
IUnknown_Release(punk);
}
hres = IUnknown_QueryInterface(punk, riid, ppobj);
if (FAILED(hres)) {
*ppobj = NULL;
return hres;
}
IUnknown_Release(punk);
return hres;
}
static HRESULT WINAPI DSCF_LockServer(LPCLASSFACTORY iface,BOOL dolock) {
static HRESULT WINAPI DSCF_LockServer(LPCLASSFACTORY iface,BOOL dolock)
{
IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
FIXME("(%p)->(%d),stub!\n",This,dolock);
return S_OK;
......
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