Avoid to close invalid handle

This could happen if open() return -1.
This commit is contained in:
Andrea Mazzoleni 2016-07-26 20:51:20 +02:00
parent ef6958b410
commit 0b4aee793a

View file

@ -201,7 +201,6 @@ int parity_create(struct snapraid_parity_handle* handle, const struct snapraid_p
split->f = -1;
split->size = parity->split_map[s].size;
split->limit_size = PARITY_LIMIT(limit_size, s, level);
++handle->split_mac;
/* opening in sequential mode in Windows */
flags = O_RDWR | O_CREAT | O_BINARY | advise_flags(&split->advise);
@ -213,6 +212,9 @@ int parity_create(struct snapraid_parity_handle* handle, const struct snapraid_p
/* LCOV_EXCL_STOP */
}
/* we have a valid file handle */
++handle->split_mac;
/* get the stat info */
ret = fstat(split->f, &split->st);
if (ret != 0) {
@ -558,7 +560,6 @@ int parity_open(struct snapraid_parity_handle* handle, const struct snapraid_par
split->f = -1;
split->size = parity->split_map[s].size;
split->limit_size = PARITY_LIMIT(limit_size, s, level);
++handle->split_mac;
/* open for read */
/* O_NOATIME: do not change access time */
@ -570,6 +571,9 @@ int parity_open(struct snapraid_parity_handle* handle, const struct snapraid_par
goto bail;
}
/* we have a valid file handle */
++handle->split_mac;
/* get the stat info */
ret = fstat(split->f, &split->st);
if (ret != 0) {