{
va_list args;
- char *tmp = Util_SafeMalloc(MAXSTRING);
+ char *tmp = malloc(MAXSTRING);
- va_start(args, fmtstr);
- Str_Vsnprintf(tmp, MAXSTRING, fmtstr, args);
- va_end(args);
+ if (tmp != NULL) {
+ va_start(args, fmtstr);
+ Str_Vsnprintf(tmp, MAXSTRING, fmtstr, args);
+ va_end(args);
- sLog(log_error, "Panic callback invoked: '%s'.\n", tmp);
+ sLog(log_error, "Panic callback invoked: '%s'.\n", tmp);
- free(tmp);
+ free(tmp);
+ } else {
+ sLog(log_error, "Error allocating memory to log panic messages\n");
+ }
exit(1);
}
#ifdef VMX86_DEBUG
va_list args;
- char *tmp = Util_SafeMalloc(MAXSTRING);
+ char *tmp = malloc(MAXSTRING);
- va_start(args, fmtstr);
- Str_Vsnprintf(tmp, MAXSTRING, fmtstr, args);
- va_end(args);
+ if (tmp != NULL) {
+ va_start(args, fmtstr);
+ Str_Vsnprintf(tmp, MAXSTRING, fmtstr, args);
+ va_end(args);
- sLog(log_debug, "Debug callback invoked: '%s'.\n", tmp);
+ sLog(log_debug, "Debug callback invoked: '%s'.\n", tmp);
- free(tmp);
+ free(tmp);
+ } else {
+ sLog(log_error, "Error allocating memory to log debug messages\n");
+ }
#endif
}
size_t responseLength = 0;
Bool success;
- if (errMsg) {
+ if (errMsg != NULL) {
int msg_size = strlen(CABCOMMANDLOG) + 1 + strlen(errMsg) + 1;
msg = malloc(msg_size);
if (msg == NULL) {
char* tmp = malloc(MAXSTRING);
- if (tmp) {
+ if (tmp != NULL) {
va_start(args, format);
Str_Vsnprintf(tmp, MAXSTRING, format, args);
va_end(args);
}
- if (gDeployError) {
+ if (gDeployError != NULL) {
free(gDeployError);
gDeployError = NULL;
}
sLog(log_debug, "Adding to list '%s'.\n", token);
#endif
data = malloc(strlen(token) + 1);
- if (!data) {
+ if (data == NULL) {
SetDeployError("Error allocating memory. (%s)", strerror(errno));
return NULL;
}
strcpy(data, token);
l = malloc(sizeof(struct List));
- if (!l) {
+ if (l == NULL) {
SetDeployError("Error allocating memory. (%s)", strerror(errno));
// clear allocated resource
free(data);
tail = tail->next;
}
- if (tail) {
+ if (tail != NULL) {
tail->next = l;
}
// Create space and copy the command
*command = malloc(VMWAREDEPLOYPKG_CMD_LENGTH);
- if (!*command) {
+ if (*command == NULL) {
SetDeployError("Error allocating memory.");
return FALSE;
}
int fd;
sLog(log_info, "ENTER STATE '%s'.\n", state);
- if (!fileName) {
+ if (fileName == NULL) {
SetDeployError("Error allocating memory.");
return DEPLOYPKG_STATUS_ERROR;
}
int result;
sLog(log_info, "EXIT STATE '%s'.\n", state);
- if (!fileName) {
+ if (fileName == NULL) {
SetDeployError("Error allocating memory.");
return DEPLOYPKG_STATUS_ERROR;
}
sLog(log_info, "Transitioning from state '%s' to state '%s'.\n", stateFrom, stateTo);
// Create a file to indicate state to
- if (stateTo) {
+ if (stateTo != NULL) {
if (Touch(stateTo) == DEPLOYPKG_STATUS_ERROR) {
SetDeployError("Error creating new state '%s'.(%s)", stateTo, GetDeployError());
return DEPLOYPKG_STATUS_ERROR;
}
// Remove the old state file
- if (stateFrom) {
+ if (stateFrom != NULL) {
if (UnTouch(stateFrom) == DEPLOYPKG_STATUS_ERROR) {
SetDeployError("Error deleting old state '%s'.(%s)", stateFrom, GetDeployError());
return DEPLOYPKG_STATUS_ERROR;
} else {
char *nics = GetNicsToEnable(imcDirPath);
- if (nics) {
+ if (nics != NULL) {
// XXX: Sleep before the last SetCustomizationStatusInVmx
// This is a temporary-hack for PR 422790
sleep(5);
}
cleanupCommandSize = strlen(CLEANUPCMD) + strlen(imcDirPath) + 1;
cleanupCommand = malloc(cleanupCommandSize);
- if (!cleanupCommand) {
+ if (cleanupCommand == NULL) {
SetDeployError("Error allocating memory.");
free(imcDirPath);
return DEPLOYPKG_STATUS_ERROR;
}
// check if cab file is set
- if (!cabFileName) {
+ if (cabFileName == NULL) {
SetDeployError("Cab file not set.");
return FALSE;
}
// prefixing the start path for the commands
args = malloc((ListSize(commandTokens) + 1) * sizeof(char*));
- if (!args) {
+ if (args == NULL) {
SetDeployError("Error allocating memory.");
// clear resources
DeleteList(commandTokens);
for(l = commandTokens, i = 0; l; l = l->next, i++) {
char* arg = malloc(strlen(l->data) + 1);
- if (!arg) {
+ if (arg == NULL) {
unsigned int j;
SetDeployError("Error allocating memory. (%s)", strerror(errno));
// free allocated memories in previous iterations if any
#include <unistd.h>
#include <fcntl.h>
#include <sys/wait.h>
+#include <stdlib.h>
#include "util.h"
Process_Create(ProcessHandle *h, char *args[], void *logPtr)
{
int i, numArgs;
+ int err = -1;
ProcessInternal *p;
LogFunction log = (LogFunction)logPtr;
log(log_info, "sizeof ProcessInternal is %d\n", sizeof(ProcessInternal));
- p = Util_SafeMalloc(sizeof(ProcessInternal));
- p->stdoutStr = Util_SafeMalloc(sizeof(char));
+ p = (ProcessInternal*) calloc(1, sizeof(ProcessInternal));
+ if (p == NULL) {
+ log(log_error, "Error allocating memory for process\n");
+ goto error;
+ }
+ p->stdoutStr = malloc(sizeof(char));
+ if (p->stdoutStr == NULL) {
+ log(log_error, "Error allocating memory for process stdout\n");
+ goto error;
+ }
p->stdoutStr[0] = '\0';
- p->stderrStr = Util_SafeMalloc(sizeof(char));
+ p->stderrStr = malloc(sizeof(char));
+ if (p->stderrStr == NULL) {
+ log(log_error, "Error allocating memory for process stderr\n");
+ goto error;
+ }
p->stderrStr[0] = '\0';
p->stdoutFd = -1;
numArgs++;
}
- p->args = Util_SafeMalloc((1 + numArgs) * sizeof(char*));
+ p->args = malloc((1 + numArgs) * sizeof(char*));
+ if (p->args == NULL) {
+ log(log_error, "Error allocating memory for process args\n");
+ goto error;
+ }
for (i = 0; i < numArgs; i++) {
- p->args[i] = Util_SafeStrdup(args[i]);
+ p->args[i] = strdup(args[i]);
+ if (p->args[i] == NULL) {
+ log(log_error, "Error allocating memory for duplicate args\n");
+ goto error;
+ }
}
- p->args[numArgs] = (char*)0;
+ p->args[numArgs] = NULL;
p->log = log;
*h = (ProcessHandle)p;
+ err = 0;
+
+error:
+ if (err != 0) {
+ if (p != NULL) {
+ Process_Destroy((ProcessHandle)p);
+ }
+ exit(1);
+ }
return PROCESS_SUCCESS;
}
} else if (p->pid == 0) {
// we're in the child. close the read ends of the pipes and exec
close(stdout[0]);
- close(stderr[0]);
+ close(stderr[0]);
dup2(stdout[1], STDOUT_FILENO);
dup2(stderr[1], STDERR_FILENO);
execv(p->args[0], p->args);
}
free(p->stdoutStr);
free(p->stderrStr);
- for (i = 0; p->args[i] != NULL; i++) {
- free(p->args[i]);
+ if (p->args != NULL) {
+ for (i = 0; p->args[i] != NULL; i++) {
+ free(p->args[i]);
+ }
+ free(p->args);
}
- free(p->args);
free(p);
return PROCESS_SUCCESS;
}