rts/win32: Assert that the IO manager has been initialised
authorSimon Jakobi <simon.jakobi@gmail.com>
Fri, 2 Mar 2018 21:13:26 +0000 (16:13 -0500)
committerBen Gamari <ben@smart-cactus.org>
Fri, 2 Mar 2018 21:13:28 +0000 (16:13 -0500)
Reviewers: bgamari, erikd, simonmar

Reviewed By: bgamari

Subscribers: rwbarton, thomie, carter

Differential Revision: https://phabricator.haskell.org/D4450

rts/win32/IOManager.c

index 216e725..f155180 100644 (file)
@@ -435,13 +435,12 @@ AddIORequest ( int   fd,
                char* buffer,
                CompletionProc onCompletion)
 {
+    ASSERT(ioMan);
+
     WorkItem* wItem    = (WorkItem*)malloc(sizeof(WorkItem));
-    unsigned int reqID;
-    if (!ioMan || !wItem) {
-        free(wItem);
-        return 0;
-    }
-    reqID = ioMan->requestID++;
+    if (!wItem) return 0;
+
+    unsigned int reqID = ioMan->requestID++;
 
     /* Fill in the blanks */
     wItem->workKind     = ( isSocket   ? WORKER_FOR_SOCKET : 0 ) |
@@ -467,13 +466,12 @@ BOOL
 AddDelayRequest ( HsInt          usecs,
                   CompletionProc onCompletion)
 {
+    ASSERT(ioMan);
+
     WorkItem* wItem = (WorkItem*)malloc(sizeof(WorkItem));
-    unsigned int reqID;
-    if (!ioMan || !wItem) {
-        free(wItem);
-        return false;
-    }
-    reqID = ioMan->requestID++;
+    if (!wItem) return false;
+
+    unsigned int reqID = ioMan->requestID++;
 
     /* Fill in the blanks */
     wItem->workKind     = WORKER_DELAY;
@@ -495,13 +493,12 @@ AddProcRequest ( void* proc,
                  void* param,
                  CompletionProc onCompletion)
 {
+    ASSERT(ioMan);
+
     WorkItem* wItem = (WorkItem*)malloc(sizeof(WorkItem));
-    unsigned int reqID;
-    if (!ioMan || !wItem) {
-        free(wItem);
-        return false;
-    }
-    reqID = ioMan->requestID++;
+    if (!wItem) return false;
+
+    unsigned int reqID = ioMan->requestID++;
 
     /* Fill in the blanks */
     wItem->workKind     = WORKER_DO_PROC;