properly free memory/close fd upon errors (Thanks xeen)
Found with the static analyzer cppcheck
This commit is contained in:
parent
69dc632a4e
commit
e1631d6320
|
@ -188,6 +188,7 @@ static char *migrate_config(char *input, off_t size) {
|
|||
ret = read(readpipe[0], converted + read_bytes, conv_size - read_bytes);
|
||||
if (ret == -1) {
|
||||
warn("Cannot read from pipe");
|
||||
FREE(converted);
|
||||
return NULL;
|
||||
}
|
||||
read_bytes += ret;
|
||||
|
|
|
@ -59,8 +59,10 @@ static bool mkdirp(const char *path) {
|
|||
copy[strlen(copy)-1] = '\0';
|
||||
|
||||
char *sep = strrchr(copy, '/');
|
||||
if (sep == NULL)
|
||||
if (sep == NULL) {
|
||||
FREE(copy);
|
||||
return false;
|
||||
}
|
||||
*sep = '\0';
|
||||
bool result = false;
|
||||
if (mkdirp(copy))
|
||||
|
|
|
@ -374,11 +374,13 @@ char *store_restart_layout() {
|
|||
if (n == -1) {
|
||||
perror("write()");
|
||||
free(filename);
|
||||
close(fd);
|
||||
return NULL;
|
||||
}
|
||||
if (n == 0) {
|
||||
printf("write == 0?\n");
|
||||
free(filename);
|
||||
close(fd);
|
||||
return NULL;
|
||||
}
|
||||
written += n;
|
||||
|
|
Loading…
Reference in New Issue