diff options
-rw-r--r-- | src/utils.c | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/src/utils.c b/src/utils.c index e7d6b69..deb36f8 100644 --- a/src/utils.c +++ b/src/utils.c @@ -254,12 +254,12 @@ struct Lock *device_lock(const char *path) struct Lock *result = (struct Lock*)calloc(1, sizeof(struct Lock)); if (result == NULL) { log_error("out of memory"); - return NULL; + return device_unlock(result); } if (asprintf(&result->path, "/var/lock/LCK..%s", basename(path)) < 0) { log_error("out of memory"); - return NULL; + return device_unlock(result); } result->fd = open(result->path, O_CREAT | O_RDWR, 0644); @@ -279,9 +279,8 @@ struct Lock *device_lock(const char *path) usleep(100000ul);//100ms } log_error("failed to create %s: %m", result->path); - device_unlock(result); } - return NULL; + return device_unlock(result); } struct Lock *device_unlock(struct Lock *lock) @@ -289,6 +288,7 @@ struct Lock *device_unlock(struct Lock *lock) if (lock) { close(lock->fd); free(lock->path); + lock->path = NULL; free(lock); } return NULL; |