commit 2acfca77da819090c3caac77635cb2c2bc4ebe14 from: Stefan Sperling date: Sun Apr 01 15:44:32 2018 UTC don't forgot to close blobs after diffing them commit - 254707814d845a2c4a93c473ad51e9e1b28c716f commit + 2acfca77da819090c3caac77635cb2c2bc4ebe14 blob - 9f91bda196d6d4744786e5335ea8b475d850df49 blob + 97a6d9ef1386a1ea8f3b9b8d666bd8b3bcbf27b2 --- lib/diff.c +++ lib/diff.c @@ -153,17 +153,22 @@ diff_added_blob(struct got_object_id *id, struct got_r 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 g } 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 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 *