int saved_errno;
int ret;
int status;
- char *tmp = NULL;
+ VIR_AUTOFREE(char *) tmp = NULL;
if (pid <= 0)
return;
VIR_DEBUG("failed to reap child %lld, abandoning it", (long long) pid);
cleanup:
- VIR_FREE(tmp);
errno = saved_errno;
}
#else
{
int ret;
int status;
+ VIR_AUTOFREE(char *) st = NULL;
if (pid <= 0) {
if (pid != -1)
return 0;
error:
- {
- char *st = virProcessTranslateStatus(status);
- virReportError(VIR_ERR_INTERNAL_ERROR,
- _("Child process (%lld) unexpected %s"),
- (long long) pid, NULLSTR(st));
- VIR_FREE(st);
- }
+ st = virProcessTranslateStatus(status);
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ _("Child process (%lld) unexpected %s"),
+ (long long) pid, NULLSTR(st));
return -1;
}
int virProcessGetPids(pid_t pid, size_t *npids, pid_t **pids)
{
int ret = -1;
- char *taskPath = NULL;
DIR *dir = NULL;
int value;
struct dirent *ent;
+ VIR_AUTOFREE(char *) taskPath = NULL;
*npids = 0;
*pids = NULL;
cleanup:
VIR_DIR_CLOSE(dir);
- VIR_FREE(taskPath);
if (ret < 0)
VIR_FREE(*pids);
return ret;
int **fdlist)
{
int ret = -1;
- char *nsfile = NULL;
size_t i = 0;
const char *ns[] = { "user", "ipc", "uts", "net", "pid", "mnt" };
for (i = 0; i < ARRAY_CARDINALITY(ns); i++) {
int fd;
+ VIR_AUTOFREE(char *) nsfile = NULL;
if (virAsprintf(&nsfile, "/proc/%llu/ns/%s",
(long long) pid,
(*fdlist)[(*nfdlist)-1] = fd;
}
-
- VIR_FREE(nsfile);
}
ret = 0;
cleanup:
- VIR_FREE(nsfile);
if (ret < 0) {
for (i = 0; i < *nfdlist; i++)
VIR_FORCE_CLOSE((*fdlist)[i]);
int virProcessGetStartTime(pid_t pid,
unsigned long long *timestamp)
{
- char *filename = NULL;
- char *buf = NULL;
char *tmp;
int ret = -1;
int len;
char **tokens = NULL;
+ VIR_AUTOFREE(char *) filename = NULL;
+ VIR_AUTOFREE(char *) buf = NULL;
if (virAsprintf(&filename, "/proc/%llu/stat", (long long) pid) < 0)
return -1;
cleanup:
virStringListFree(tokens);
- VIR_FREE(filename);
- VIR_FREE(buf);
return ret;
}
#elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
virProcessNamespaceCallback cb,
void *opaque)
{
- char *path;
int fd = -1;
int ret = -1;
+ VIR_AUTOFREE(char *) path = NULL;
if (virAsprintf(&path, "/proc/%lld/ns/mnt", (long long) pid) < 0)
goto cleanup;
ignore_value(safewrite(errfd, err->message, len));
}
}
- VIR_FREE(path);
VIR_FORCE_CLOSE(fd);
return ret;
}
VIR_FORCE_CLOSE(errfd[1]);
_exit(ret < 0 ? EXIT_CANCELED : ret);
} else {
- char *buf = NULL;
int status;
+ VIR_AUTOFREE(char *) buf = NULL;
VIR_FORCE_CLOSE(errfd[1]);
ignore_value(virFileReadHeaderFD(errfd[0], 1024, &buf));
NULLSTR(buf));
}
}
- VIR_FREE(buf);
}
cleanup:
int flags = 0;
int cpid;
char *childStack;
- char *stack;
int stacksize = getpagesize() * 4;
+ VIR_AUTOFREE(char *)stack = NULL;
if (ns & VIR_PROCESS_NAMESPACE_MNT)
flags |= CLONE_NEWNS;
childStack = stack + stacksize;
cpid = clone(virProcessDummyChild, childStack, flags, NULL);
- VIR_FREE(stack);
+
if (cpid < 0) {
char ebuf[1024] ATTRIBUTE_UNUSED;
VIR_DEBUG("clone call returned %s, container support is not enabled",