diff options
| author | Hauke Mehrtens | 2019-11-01 11:02:13 +0000 |
|---|---|---|
| committer | Hauke Mehrtens | 2019-11-01 15:58:14 +0000 |
| commit | 2c8e4a347bb68229937ceda6e099fb10e9b792d1 (patch) | |
| tree | 7b0f8e2bea43e12174566035ac8d5c062d8b74aa | |
| parent | 415f9e48436d29f612348f58f546b3ad8d74ac38 (diff) | |
| download | uci-2c8e4a347bb68229937ceda6e099fb10e9b792d1.tar.gz | |
util: Fix error path
Unlock and close the stream in case some file operations in
uci_open_stream() fail.
Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
| -rw-r--r-- | util.c | 8 |
1 files changed, 6 insertions, 2 deletions
@@ -221,17 +221,21 @@ __private FILE *uci_open_stream(struct uci_context *ctx, const char *filename, c ret = flock(fd, (write ? LOCK_EX : LOCK_SH)); if ((ret < 0) && (errno != ENOSYS)) - goto error; + goto error_close; ret = lseek(fd, 0, pos); if (ret < 0) - goto error; + goto error_unlock; file = fdopen(fd, (write ? "w+" : "r")); if (file) goto done; +error_unlock: + flock(fd, LOCK_UN); +error_close: + close(fd); error: UCI_THROW(ctx, UCI_ERR_IO); done: |