Author: hbelusca
Date: Fri Mar 3 23:47:26 2017
New Revision: 74043
URL:
http://svn.reactos.org/svn/reactos?rev=74043&view=rev
Log:
[WS2_32]
- Check for NULL pointers after HeapAlloc calls, in the constructor functions, before
initializing members of created objects;
- Add a bunch of missing HeapFree in the corresponding destructor functions.
In particular, fix the root cause of CID 1401152 in WsTpDelete: missing HeapFree call.
CORE-12880
Modified:
trunk/reactos/dll/win32/ws2_32/src/dcatitem.c
trunk/reactos/dll/win32/ws2_32/src/dprocess.c
trunk/reactos/dll/win32/ws2_32/src/dprovide.c
trunk/reactos/dll/win32/ws2_32/src/dsocket.c
trunk/reactos/dll/win32/ws2_32/src/dthread.c
trunk/reactos/dll/win32/ws2_32/src/nscatent.c
trunk/reactos/dll/win32/ws2_32/src/nsprovid.c
trunk/reactos/dll/win32/ws2_32/src/nsquery.c
Modified: trunk/reactos/dll/win32/ws2_32/src/dcatitem.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/ws2_32/src/dcati…
==============================================================================
--- trunk/reactos/dll/win32/ws2_32/src/dcatitem.c [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/ws2_32/src/dcatitem.c [iso-8859-1] Fri Mar 3 23:47:26 2017
@@ -20,9 +20,11 @@
/* Allocate the catalog entry */
CatalogEntry = HeapAlloc(WsSockHeap, HEAP_ZERO_MEMORY, sizeof(*CatalogEntry));
-
- /* Set the default non-null members */
- CatalogEntry->RefCount = 1;
+ if (CatalogEntry)
+ {
+ /* Set the default non-null members */
+ CatalogEntry->RefCount = 1;
+ }
/* Return it */
return CatalogEntry;
Modified: trunk/reactos/dll/win32/ws2_32/src/dprocess.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/ws2_32/src/dproc…
==============================================================================
--- trunk/reactos/dll/win32/ws2_32/src/dprocess.c [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/ws2_32/src/dprocess.c [iso-8859-1] Fri Mar 3 23:47:26 2017
@@ -37,6 +37,8 @@
Process->ProtocolCatalogEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
Process->ProtocolCatalog = WsTcAllocate();
+ // FIXME: Check for Process->ProtocolCatalog == NULL
+
/* Initialize it */
WsTcInitializeFromRegistry(Process->ProtocolCatalog,
RootKey,
@@ -46,6 +48,8 @@
Process->NamespaceCatalogEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
Process->NamespaceCatalog = WsNcAllocate();
+ // FIXME: Check for Process->NamespaceCatalog == NULL
+
/* Initialize it */
ErrorCode = WsNcInitializeFromRegistry(Process->NamespaceCatalog,
RootKey,
@@ -64,9 +68,11 @@
/* Allocate the structure */
Process = HeapAlloc(WsSockHeap, HEAP_ZERO_MEMORY, sizeof(*Process));
-
- /* Set default non-zero values */
- Process->Version = MAKEWORD(2,2);
+ if (Process)
+ {
+ /* Set default non-zero values */
+ Process->Version = MAKEWORD(2,2);
+ }
/* Return it */
return Process;
@@ -296,6 +302,9 @@
/* Delete the thread lock */
DeleteCriticalSection(&Process->ThreadLock);
+
+ /* Delete us */
+ HeapFree(WsSockHeap, 0, Process);
}
VOID
Modified: trunk/reactos/dll/win32/ws2_32/src/dprovide.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/ws2_32/src/dprov…
==============================================================================
--- trunk/reactos/dll/win32/ws2_32/src/dprovide.c [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/ws2_32/src/dprovide.c [iso-8859-1] Fri Mar 3 23:47:26 2017
@@ -21,12 +21,13 @@
{
PTPROVIDER Provider;
- DPRINT("WsTpAllocate: WsSockHeap %d\n", WsSockHeap);
/* Allocate the object */
Provider = HeapAlloc(WsSockHeap, HEAP_ZERO_MEMORY, sizeof(*Provider));
-
- /* Setup non-zero data */
- Provider->RefCount = 1;
+ if (Provider)
+ {
+ /* Setup non-zero data */
+ Provider->RefCount = 1;
+ }
/* Return it */
return Provider;
@@ -130,10 +131,11 @@
/* Unload the library */
FreeLibrary(Provider->DllHandle);
-
- /* Clear the handle value */
Provider->DllHandle = NULL;
}
+
+ /* Delete us */
+ HeapFree(WsSockHeap, 0, Provider);
}
VOID
Modified: trunk/reactos/dll/win32/ws2_32/src/dsocket.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/ws2_32/src/dsock…
==============================================================================
--- trunk/reactos/dll/win32/ws2_32/src/dsocket.c [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/ws2_32/src/dsocket.c [iso-8859-1] Fri Mar 3 23:47:26 2017
@@ -50,11 +50,13 @@
PWSSOCKET Socket;
/* Allocate the socket object */
- Socket = HeapAlloc(WsSockHeap, HEAP_ZERO_MEMORY, sizeof(WSSOCKET));
-
- /* Setup default non-zero values */
- Socket->RefCount = 2;
- Socket->Overlapped = TRUE;
+ Socket = HeapAlloc(WsSockHeap, HEAP_ZERO_MEMORY, sizeof(*Socket));
+ if (Socket)
+ {
+ /* Setup default non-zero values */
+ Socket->RefCount = 2;
+ Socket->Overlapped = TRUE;
+ }
/* Return it */
return Socket;
@@ -193,6 +195,9 @@
WsTcEntryDereference(Socket->CatalogEntry);
Socket->CatalogEntry = NULL;
}
+
+ /* Delete us */
+ HeapFree(WsSockHeap, 0, Socket);
}
VOID
Modified: trunk/reactos/dll/win32/ws2_32/src/dthread.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/ws2_32/src/dthre…
==============================================================================
--- trunk/reactos/dll/win32/ws2_32/src/dthread.c [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/ws2_32/src/dthread.c [iso-8859-1] Fri Mar 3 23:47:26 2017
@@ -138,9 +138,11 @@
/* Allocate the object */
Thread = HeapAlloc(WsSockHeap, HEAP_ZERO_MEMORY, sizeof(*Thread));
-
- /* Set non-zero data */
- Thread->BlockingHook = (FARPROC)WsThreadDefaultBlockingHook;
+ if (Thread)
+ {
+ /* Set non-zero data */
+ Thread->BlockingHook = (FARPROC)WsThreadDefaultBlockingHook;
+ }
/* Return it */
return Thread;
Modified: trunk/reactos/dll/win32/ws2_32/src/nscatent.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/ws2_32/src/nscat…
==============================================================================
--- trunk/reactos/dll/win32/ws2_32/src/nscatent.c [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/ws2_32/src/nscatent.c [iso-8859-1] Fri Mar 3 23:47:26 2017
@@ -20,11 +20,13 @@
/* Allocate the catalog */
CatalogEntry = HeapAlloc(WsSockHeap, HEAP_ZERO_MEMORY, sizeof(*CatalogEntry));
-
- /* Set the default non-null members */
- CatalogEntry->RefCount = 1;
- CatalogEntry->Enabled = TRUE;
- CatalogEntry->AddressFamily = -1;
+ if (CatalogEntry)
+ {
+ /* Set the default non-null members */
+ CatalogEntry->RefCount = 1;
+ CatalogEntry->Enabled = TRUE;
+ CatalogEntry->AddressFamily = -1;
+ }
/* Return it */
return CatalogEntry;
Modified: trunk/reactos/dll/win32/ws2_32/src/nsprovid.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/ws2_32/src/nspro…
==============================================================================
--- trunk/reactos/dll/win32/ws2_32/src/nsprovid.c [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/ws2_32/src/nsprovid.c [iso-8859-1] Fri Mar 3 23:47:26 2017
@@ -66,12 +66,14 @@
/* Allocate the object */
Provider = HeapAlloc(WsSockHeap, HEAP_ZERO_MEMORY, sizeof(*Provider));
-
- /* Set non-null data */
- Provider->RefCount = 1;
- Provider->Service.cbSize = sizeof(NSP_ROUTINE);
-
- /* Return us */
+ if (Provider)
+ {
+ /* Set non-null data */
+ Provider->RefCount = 1;
+ Provider->Service.cbSize = sizeof(NSP_ROUTINE);
+ }
+
+ /* Return it */
return Provider;
}
@@ -129,6 +131,7 @@
Fail:
/* Bail out */
if (Provider->DllHandle) FreeLibrary(Provider->DllHandle);
+ Provider->DllHandle = NULL;
return ErrorCode;
}
@@ -165,10 +168,11 @@
/* Unload the library */
FreeLibrary(Provider->DllHandle);
-
- /* Clear the handle value */
Provider->DllHandle = NULL;
}
+
+ /* Delete us */
+ HeapFree(WsSockHeap, 0, Provider);
}
VOID
Modified: trunk/reactos/dll/win32/ws2_32/src/nsquery.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/ws2_32/src/nsque…
==============================================================================
--- trunk/reactos/dll/win32/ws2_32/src/nsquery.c [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/ws2_32/src/nsquery.c [iso-8859-1] Fri Mar 3 23:47:26 2017
@@ -25,11 +25,13 @@
/* Allocate the object */
NsQuery = HeapAlloc(WsSockHeap, HEAP_ZERO_MEMORY, sizeof(*NsQuery));
-
- /* Set non-zero fields */
- NsQuery->Signature = ~0xBEADFACE;
- InitializeListHead(&NsQuery->ProviderList);
- NsQuery->TryAgain = TRUE;
+ if (NsQuery)
+ {
+ /* Set non-zero fields */
+ NsQuery->Signature = ~0xBEADFACE;
+ InitializeListHead(&NsQuery->ProviderList);
+ NsQuery->TryAgain = TRUE;
+ }
/* Return it */
return NsQuery;