From 3775f2cc016eefc615c1adc4a22b16ea7b010a91 Mon Sep 17 00:00:00 2001 From: Maksym Telychko Date: Tue, 14 Apr 2020 19:16:13 +0300 Subject: MTX-3262 mpower: fix memory leak --- src/utils.c | 8 ++++---- 1 file 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; -- cgit v1.2.3