Commit 23bada3c authored by Milan Broz's avatar Milan Broz

Fix several issues found by Coverity scan.

parent de0cf843
......@@ -246,7 +246,7 @@ int crypt_storage_decrypt(struct crypt_storage *ctx,
uint64_t iv_offset,
uint64_t length, char *buffer)
{
unsigned int i;
uint64_t i;
int r = 0;
if (length & ((1 << ctx->sector_shift) - 1))
......@@ -275,7 +275,7 @@ int crypt_storage_encrypt(struct crypt_storage *ctx,
uint64_t iv_offset,
uint64_t length, char *buffer)
{
unsigned int i;
uint64_t i;
int r = 0;
if (length & ((1 << ctx->sector_shift) - 1))
......
......@@ -301,12 +301,12 @@ static unsigned device_lock_dec(struct crypt_lock_handle *h)
static int acquire_and_verify(struct crypt_device *cd, struct device *device, const char *resource, int flock_op, struct crypt_lock_handle **lock)
{
int r;
struct crypt_lock_handle *h = malloc(sizeof(*h));
struct crypt_lock_handle *h;
if (device && resource)
return -EINVAL;
if (!h)
if (!(h = malloc(sizeof(*h))))
return -ENOMEM;
do {
......@@ -329,7 +329,8 @@ static int acquire_and_verify(struct crypt_device *cd, struct device *device, co
*/
r = verify_lock_handle(device_path(device), h);
if (r) {
flock(h->flock_fd, LOCK_UN);
if (flock(h->flock_fd, LOCK_UN))
log_dbg(cd, "flock on fd %d failed.", h->flock_fd);
release_lock_handle(cd, h);
log_dbg(cd, "Lock handle verification failed.");
}
......@@ -337,7 +338,7 @@ static int acquire_and_verify(struct crypt_device *cd, struct device *device, co
if (r) {
free(h);
return r;
return -EINVAL;
}
*lock = h;
......
......@@ -185,6 +185,7 @@ int crypt_storage_wrapper_init(struct crypt_device *cd,
return -ENOMEM;
memset(w, 0, sizeof(*w));
w->dev_fd = -1;
w->data_offset = data_offset;
w->mem_alignment = device_alignment(device);
w->block_size = device_block_size(cd, device);
......@@ -376,7 +377,8 @@ void crypt_storage_wrapper_destroy(struct crypt_storage_wrapper *cw)
dm_remove_device(NULL, cw->u.dm.name, CRYPT_DEACTIVATE_FORCE);
}
close(cw->dev_fd);
if (cw->dev_fd >= 0)
close(cw->dev_fd);
free(cw);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment