diff options
author | Maksym Telychko <maksym.telychko@globallogic.com> | 2020-04-14 19:16:13 +0300 |
---|---|---|
committer | Maksym Telychko <maksym.telychko@globallogic.com> | 2020-04-18 09:02:18 +0300 |
commit | 3775f2cc016eefc615c1adc4a22b16ea7b010a91 (patch) | |
tree | 7e14009f18af8db48deb674f8a5f2f88b92a6be7 | |
parent | d48fa68d6207b25061d5276021b1dd25ce5da89d (diff) | |
download | sms-utils-3775f2cc016eefc615c1adc4a22b16ea7b010a91.tar.gz sms-utils-3775f2cc016eefc615c1adc4a22b16ea7b010a91.tar.bz2 sms-utils-3775f2cc016eefc615c1adc4a22b16ea7b010a91.zip |
MTX-3262 mpower: fix memory leak
-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; |