[RESENT] Split patch part 1 for reference counting bug in storage32 (bug #4436 part 1)

Dr J A Gow J.A.Gow at furrybubble.co.uk
Mon Feb 20 14:03:35 CST 2006


FROM:   Dr J A Gow
PATCH:  Part 1 of fix for bug 4436
         - Stream methods called after parent object has been closed
           correctly return STG_E_REVERTED
         - Stream refcounting fixed. Now can safely call IStorage
           destructor before IStream destructor and guarantee file
           will be closed.



Index: wine/dlls/ole32/storage32.c
===================================================================
RCS file: /home/wine/wine/dlls/ole32/storage32.c,v
retrieving revision 1.99
diff -u -p -r1.99 storage32.c
--- wine/dlls/ole32/storage32.c	6 Jan 2006 20:51:54 -0000	1.99
+++ wine/dlls/ole32/storage32.c	19 Feb 2006 16:42:50 -0000
@@ -342,13 +342,16 @@ HRESULT WINAPI StorageBaseImpl_OpenStrea
    }

    /*
-   * Check that we're compatible with the parent's storage mode
+   * Check that we're compatible with the parent's storage mode, but
+   * only if we are not in transacted mode
     */
    parent_grfMode = STGM_ACCESS_MODE( This->ancestorStorage->base.openFlags );
-  if ( STGM_ACCESS_MODE( grfMode ) > STGM_ACCESS_MODE( parent_grfMode ) )
-  {
-    res = STG_E_ACCESSDENIED;
-    goto end;
+  if(!(This->ancestorStorage->base.openFlags & STGM_TRANSACTED)) {
+    if ( STGM_ACCESS_MODE( grfMode ) > STGM_ACCESS_MODE( parent_grfMode ) )
+    {
+      res = STG_E_ACCESSDENIED;
+      goto end;
+    }
    }

    /*
@@ -478,13 +481,16 @@ HRESULT WINAPI StorageBaseImpl_OpenStora
    }

    /*
-   * Check that we're compatible with the parent's storage mode
+   * Check that we're compatible with the parent's storage mode,
+   * but only if we are not transacted
     */
    parent_grfMode = STGM_ACCESS_MODE( This->ancestorStorage->base.openFlags );
-  if ( STGM_ACCESS_MODE( grfMode ) > STGM_ACCESS_MODE( parent_grfMode ) )
-  {
-    res = STG_E_ACCESSDENIED;
-    goto end;
+  if(!(This->ancestorStorage->base.openFlags & STGM_TRANSACTED)) {
+    if ( STGM_ACCESS_MODE( grfMode ) > STGM_ACCESS_MODE( parent_grfMode ) )
+    {
+      res = STG_E_ACCESSDENIED;
+      goto end;
+    }
    }

    /*
@@ -875,10 +881,13 @@ HRESULT WINAPI StorageBaseImpl_CreateStr

    /*
     * Check that we're compatible with the parent's storage mode
+   * if not in transacted mode
     */
    parent_grfMode = STGM_ACCESS_MODE( This->ancestorStorage->base.openFlags );
-  if ( STGM_ACCESS_MODE( grfMode ) > STGM_ACCESS_MODE( parent_grfMode ) )
-    return STG_E_ACCESSDENIED;
+  if(!(parent_grfMode & STGM_TRANSACTED)) {
+    if ( STGM_ACCESS_MODE( grfMode ) > STGM_ACCESS_MODE( parent_grfMode ) )
+      return STG_E_ACCESSDENIED;
+  }

    /*
     * Initialize the out parameter
Index: wine/dlls/ole32/tests/storage32.c
===================================================================
RCS file: /home/wine/wine/dlls/ole32/tests/storage32.c,v
retrieving revision 1.15
diff -u -p -r1.15 storage32.c
--- wine/dlls/ole32/tests/storage32.c	15 Feb 2006 13:03:12 -0000	1.15
+++ wine/dlls/ole32/tests/storage32.c	19 Feb 2006 16:42:52 -0000
@@ -593,7 +593,13 @@ static void test_storage_refcount(void)
      r = IStorage_CreateStream(stg, stmname, STGM_SHARE_EXCLUSIVE | STGM_READWRITE, 0, 0, &stm );
      ok(r==S_OK, "IStorage->CreateStream failed\n");

-    todo_wine {
+    /* Win needs the Commit to ensure stream is created, otherwise the grfMode open
+     * tests below don't work
+     */
+
+    IStorage_Commit(stg,STGC_DEFAULT);
+    ok(r==S_OK, "IStorage->Commit failed\n");
+
      r = IStorage_Release( stg );
      ok (r == 0, "storage not released\n");

@@ -603,11 +609,23 @@ static void test_storage_refcount(void)

      r = IStream_Stat( stm, &stat, STATFLAG_DEFAULT );
      ok (r == STG_E_REVERTED, "stat should fail\n");
-    }
-
+
      r = IStream_Release(stm);
      ok (r == 0, "stream not released\n");

+    /* test for grfMode open issue */
+
+    r = StgOpenStorage( filename, NULL, 0x00010020, NULL, 0, &stg);
+    ok(r==S_OK, "StgOpenStorage failed\n");
+    if(stg)
+    {
+        r = IStorage_OpenStream( stg, stmname, 0, STGM_SHARE_EXCLUSIVE|STGM_READWRITE, 0, &stm );
+        ok(r == S_OK, "OpenStream should succeed - "); printf("rc from OpenStream : %lx\n",r);
+
+        r = IStorage_Release(stg);
+        ok(r == 0, "wrong ref count\n");
+    }
+
      DeleteFileW(filename);
  }




More information about the wine-patches mailing list