fix leftover lockfiles from parse_ref_file()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
diff --git a/lib/reference.c b/lib/reference.c
index 3f03033..ff09bbc 100644
--- a/lib/reference.c
+++ b/lib/reference.c
@@ -174,25 +174,38 @@ parse_ref_file(struct got_reference **ref, const char *name,
}
f = fopen(abspath, "rb");
- if (f == NULL)
+ if (f == NULL) {
+ if (lock)
+ got_lockfile_unlock(lf);
return NULL;
+ }
line = fparseln(f, &len, NULL, delim, 0);
if (line == NULL) {
err = got_error(GOT_ERR_BAD_REF_DATA);
+ if (lock)
+ got_lockfile_unlock(lf);
goto done;
}
err = parse_ref_line(ref, name, line);
- if (err == NULL && lf)
- (*ref)->lf = lf;
+ if (lock) {
+ if (err)
+ got_lockfile_unlock(lf);
+ else {
+ if (*ref)
+ (*ref)->lf = lf;
+ else
+ got_lockfile_unlock(lf);
+ }
+ }
done:
free(line);
if (fclose(f) != 0 && err == NULL) {
err = got_error_prefix_errno("fclose");
- if (lf)
- got_lockfile_unlock(lf);
if (*ref) {
+ if (lock)
+ got_ref_unlock(*ref);
got_ref_close(*ref);
*ref = NULL;
}