Don't cast returns from malloc()
[openafs.git] / src / procmgmt / procmgmt_nt.c
index 83e9230..bc34bfb 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * Copyright 2000, International Business Machines Corporation and others.
  * All Rights Reserved.
- * 
+ *
  * This software has been released under the terms of the IBM Public
  * License.  For details, see the LICENSE file in the top-level source
  * directory or online at http://www.openafs.org/dl/license10.html
@@ -9,27 +9,19 @@
 
 #include <afsconfig.h>
 #include <afs/param.h>
+#include <afs/stds.h>
 
-RCSID
-    ("$Header$");
+#include "procmgmt.h" /* Must be before roken */
 
-#include <afs/stds.h>
+#include <roken.h>
 
-#include <stddef.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <errno.h>
-#include <string.h>
 #include <windows.h>
 #include <pthread.h>
 #include <afs/errmap_nt.h>
 #include <afs/secutil_nt.h>
 
-#include "procmgmt.h"
 #include "pmgtprivate.h"
 
-
-
 /* Signal disposition table and associated definitions and locks */
 
 typedef struct {
@@ -251,6 +243,7 @@ static DWORD WINAPI
 RemoteSignalListenerThread(LPVOID param)
 {
     HANDLE sigPipeHandle = (HANDLE) param;
+    HMODULE hLib = LoadLibrary("AFSPROCMGMT.DLL");
 
     while (1) {
        /* wait for pipe client to connect */
@@ -296,6 +289,7 @@ RemoteSignalListenerThread(LPVOID param)
     }
 
     /* never reached */
+    FreeLibrary(hLib);
     return (0);
 }
 
@@ -552,7 +546,7 @@ StringArrayToString(char *strArray[])
     }
 
     /* put all strings into buffer; guarantee buffer is at least one char */
-    buffer = (char *)malloc(byteCount + (strCount * 3) /* quotes+space */ +1);
+    buffer = malloc(byteCount + (strCount * 3) /* quotes+space */ +1);
     if (buffer != NULL) {
        int i;
 
@@ -591,7 +585,7 @@ StringArrayToMultiString(char *strArray[])
     }
 
     /* put all strings into buffer; guarantee buffer is at least two chars */
-    buffer = (char *)malloc(byteCount + strCount + 2);
+    buffer = malloc(byteCount + strCount + 2);
     if (buffer != NULL) {
        if (byteCount == 0) {
            buffer[0] = '\0';
@@ -609,7 +603,7 @@ StringArrayToMultiString(char *strArray[])
                    bufp += strLen + 1;
                }
            }
-           bufp = '\0';        /* terminate multistring */
+           *bufp = '\0';       /* terminate multistring */
        }
     }
 
@@ -770,7 +764,7 @@ ReadChildDataBuffer(void **datap,   /* allocated data buffer */
                size_t *memp = (size_t *) bufMemp;
 
                *dataLen = *memp++;
-               *datap = (void *)malloc(*dataLen);
+               *datap = malloc(*dataLen);
 
                if (*datap != NULL) {
                    memcpy(*datap, (void *)memp, *dataLen);
@@ -882,6 +876,7 @@ pmgt_ProcessSpawnVEB(const char *spath, char *sargv[], char *senvp[],
     DWORD monitorId, createFlags;
     BOOL passingBuffer = (sdatap != NULL && sdatalen > 0);
     BOOL fsuccess;
+    int lasterror;
 
     /* verify arguments */
     if (!spath || !sargv) {
@@ -893,7 +888,7 @@ pmgt_ProcessSpawnVEB(const char *spath, char *sargv[], char *senvp[],
     }
 
     /* create path with .exe extension if no filename extension supplied */
-    if (!(pathbuf = (char *)malloc(strlen(spath) + 5 /* .exe */ ))) {
+    if (!(pathbuf = malloc(strlen(spath) + 5 /* .exe */ ))) {
        errno = ENOMEM;
        return ((pid_t) - 1);
     }
@@ -982,13 +977,14 @@ pmgt_ProcessSpawnVEB(const char *spath, char *sargv[], char *senvp[],
                             &startInfo,        /* startup info block */
                             &procInfo);
 
+    lasterror = GetLastError();
     free(pathbuf);
     free(argbuf);
     free(envbuf);
 
     if (!fsuccess) {
        /* failed to spawn process */
-       errno = nterr_nt2unix(GetLastError(), ENOENT);
+       errno = nterr_nt2unix(lasterror, ENOENT);
 
        (void)pthread_mutex_lock(&procTableLock);
        procTable[tidx].p_reserved = FALSE;     /* mark entry as not reserved */