don't forgot to close blobs after diffing them
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 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
diff --git a/lib/diff.c b/lib/diff.c
index 9f91bda..97a6d9e 100644
--- a/lib/diff.c
+++ b/lib/diff.c
@@ -153,17 +153,22 @@ diff_added_blob(struct got_object_id *id, struct got_repository *repo,
FILE *outfile)
{
const struct got_error *err;
- struct got_blob_object *blob;
- struct got_object *obj;
+ struct got_blob_object *blob = NULL;
+ struct got_object *obj = NULL;
err = got_object_open(&obj, repo, id);
if (err)
return err;
- err = got_object_blob_open(&blob, repo, obj, 8192);
- if (err != NULL)
- return err;
- return got_diff_blob(NULL, blob, NULL, NULL, outfile);
+ err = got_object_blob_open(&blob, repo, obj, 8192);
+ if (err)
+ goto done;
+ err = got_diff_blob(NULL, blob, NULL, NULL, outfile);
+done:
+ got_object_close(obj);
+ if (blob)
+ got_object_blob_close(blob);
+ return err;
}
static const struct got_error *
@@ -195,16 +200,12 @@ diff_modified_blob(struct got_object_id *id1, struct got_object_id *id2,
}
err = got_object_blob_open(&blob1, repo, obj1, 8192);
- if (err != NULL) {
- err = got_error(GOT_ERR_FILE_OPEN);
+ if (err)
goto done;
- }
err = got_object_blob_open(&blob2, repo, obj2, 8192);
- if (err != NULL) {
- err = got_error(GOT_ERR_FILE_OPEN);
+ if (err)
goto done;
- }
err = got_diff_blob(blob1, blob2, NULL, NULL, outfile);
@@ -225,17 +226,22 @@ diff_deleted_blob(struct got_object_id *id, struct got_repository *repo,
FILE *outfile)
{
const struct got_error *err;
- struct got_blob_object *blob;
- struct got_object *obj;
+ struct got_blob_object *blob = NULL;
+ struct got_object *obj = NULL;
err = got_object_open(&obj, repo, id);
if (err)
return err;
- err = got_object_blob_open(&blob, repo, obj, 8192);
- if (err != NULL)
- return err;
- return got_diff_blob(blob, NULL, NULL, NULL, outfile);
+ err = got_object_blob_open(&blob, repo, obj, 8192);
+ if (err)
+ goto done;
+ err = got_diff_blob(blob, NULL, NULL, NULL, outfile);
+done:
+ got_object_close(obj);
+ if (blob)
+ got_object_blob_close(blob);
+ return err;
}
static const struct got_error *