From b3a7f37aafa5284072cbc5cd8f2d0904e60ca636 Mon Sep 17 00:00:00 2001 From: Mike McCormack Date: Thu, 20 Jan 2005 20:34:29 +0000 Subject: [PATCH] Fix refcounting, use Interlocked functions. --- dlls/msi/handle.c | 10 +++++----- dlls/msi/msi.c | 5 ++++- dlls/msi/msipriv.h | 2 +- dlls/msi/msiquery.c | 2 ++ 4 files changed, 12 insertions(+), 7 deletions(-) diff --git a/dlls/msi/handle.c b/dlls/msi/handle.c index 194d31c6cb6..9ecfd053870 100644 --- a/dlls/msi/handle.c +++ b/dlls/msi/handle.c @@ -157,7 +157,7 @@ void msiobj_addref( MSIOBJECTHDR *info ) return; } - info->refcount++; + InterlockedIncrement(&info->refcount); } void msiobj_lock( MSIOBJECTHDR *info ) @@ -185,12 +185,12 @@ int msiobj_release( MSIOBJECTHDR *info ) return -1; } - ret = info->refcount--; - if (info->refcount == 0) + ret = InterlockedDecrement( &info->refcount ); + if( ret==0 ) { - if( info->destructor ) + if( info->destructor ) info->destructor( info ); - HeapFree( GetProcessHeap(), 0, info ); + HeapFree( GetProcessHeap(), 0, info ); TRACE("object %p destroyed\n", info); } diff --git a/dlls/msi/msi.c b/dlls/msi/msi.c index 4fc1b3b5a76..d8f98939534 100644 --- a/dlls/msi/msi.c +++ b/dlls/msi/msi.c @@ -228,9 +228,12 @@ BOOL encode_base85_guid( GUID *guid, LPWSTR str ) VOID MSI_CloseDatabase( MSIOBJECTHDR *arg ) { MSIDATABASE *db = (MSIDATABASE *) arg; + DWORD r; free_cached_tables( db ); - IStorage_Release( db->storage ); + r = IStorage_Release( db->storage ); + if( r ) + ERR("database reference count was not zero (%ld)\n", r); } UINT MSI_OpenDatabaseW(LPCWSTR szDBPath, LPCWSTR szPersist, MSIDATABASE **pdb) diff --git a/dlls/msi/msipriv.h b/dlls/msi/msipriv.h index 25bf0a913d0..bb781b2efe9 100644 --- a/dlls/msi/msipriv.h +++ b/dlls/msi/msipriv.h @@ -53,7 +53,7 @@ struct tagMSIOBJECTHDR { UINT magic; UINT type; - UINT refcount; + DWORD refcount; msihandledestructor destructor; struct tagMSIOBJECTHDR *next; struct tagMSIOBJECTHDR *prev; diff --git a/dlls/msi/msiquery.c b/dlls/msi/msiquery.c index f8a8aafe217..4f8f6d1af9f 100644 --- a/dlls/msi/msiquery.c +++ b/dlls/msi/msiquery.c @@ -461,6 +461,8 @@ UINT WINAPI MsiDatabaseCommit( MSIHANDLE hdb ) /* FIXME: unlock the database */ + msiobj_release( &db->hdr ); + return r; }