error = fstat(fd, &sb);
if (error != 0) {
emergency("fstat: %s", strerror(errno));
+ close(fd);
return (error);
}
buf = malloc(bufsize);
if (buf == NULL) {
emergency("malloc: %s", strerror(errno));
+ close(fd);
return (error);
}
nbytes = read(fd, buf, bufsize);
if (nbytes != (ssize_t)bufsize) {
emergency("read: %s", strerror(errno));
+ close(fd);
free(buf);
return (error);
}
}
static int
-create_file(const char *path, void *buf, size_t bufsize)
+create_file(const char *path, const void *buf, size_t bufsize)
{
ssize_t nbytes;
int error, fd;
nbytes = write(fd, buf, bufsize);
if (nbytes != (ssize_t)bufsize) {
emergency("write: %s", strerror(errno));
+ close(fd);
return (-1);
}
error = close(fd);
if (error != 0) {
emergency("close: %s", strerror(errno));
- free(buf);
return (-1);
}
size_t bufsize, init_path_len;
int error, name[4];
+ buf = NULL;
+ bufsize = 0;
+
name[0] = CTL_KERN;
name[1] = KERN_PROC;
name[2] = KERN_PROC_PATHNAME;
goto out;
}
- /*
- * Pacify GCC.
- */
- buf = NULL;
- bufsize = 0;
-
/*
* Copy the init binary into tmpfs, so that we can unmount
* the old rootfs without committing suicide.
out:
emergency("reroot failed; going to single user mode");
+ free(buf);
return (state_func_t) single_user;
}