object-name: free leaking object contexts
While it is documented in `struct object_context::path` that this variable needs to be released by the caller, this fact is rather easy to miss given that we do not ever provide a function to release the object context. And of course, while some callers dutifully release the path, many others don't. Introduce a new `object_context_release()` function that releases the path. Convert callsites that used to free the path to use that new function and add missing calls to callsites that were leaking memory. Refactor those callsites as required to have a single return path, only. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:

committed by
Junio C Hamano

parent
61f8bb1ec1
commit
f87c55c264
@ -102,7 +102,7 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name,
|
||||
enum object_type type;
|
||||
char *buf;
|
||||
unsigned long size;
|
||||
struct object_context obj_context;
|
||||
struct object_context obj_context = {0};
|
||||
struct object_info oi = OBJECT_INFO_INIT;
|
||||
struct strbuf sb = STRBUF_INIT;
|
||||
unsigned flags = OBJECT_INFO_LOOKUP_REPLACE;
|
||||
@ -163,7 +163,8 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name,
|
||||
goto cleanup;
|
||||
|
||||
case 'e':
|
||||
return !repo_has_object_file(the_repository, &oid);
|
||||
ret = !repo_has_object_file(the_repository, &oid);
|
||||
goto cleanup;
|
||||
|
||||
case 'w':
|
||||
|
||||
@ -268,7 +269,7 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name,
|
||||
ret = 0;
|
||||
cleanup:
|
||||
free(buf);
|
||||
free(obj_context.path);
|
||||
object_context_release(&obj_context);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -520,7 +521,7 @@ static void batch_one_object(const char *obj_name,
|
||||
struct batch_options *opt,
|
||||
struct expand_data *data)
|
||||
{
|
||||
struct object_context ctx;
|
||||
struct object_context ctx = {0};
|
||||
int flags =
|
||||
GET_OID_HASH_ANY |
|
||||
(opt->follow_symlinks ? GET_OID_FOLLOW_SYMLINKS : 0);
|
||||
@ -557,7 +558,8 @@ static void batch_one_object(const char *obj_name,
|
||||
break;
|
||||
}
|
||||
fflush(stdout);
|
||||
return;
|
||||
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (ctx.mode == 0) {
|
||||
@ -565,10 +567,13 @@ static void batch_one_object(const char *obj_name,
|
||||
(uintmax_t)ctx.symlink_path.len,
|
||||
opt->output_delim, ctx.symlink_path.buf, opt->output_delim);
|
||||
fflush(stdout);
|
||||
return;
|
||||
goto out;
|
||||
}
|
||||
|
||||
batch_object_write(obj_name, scratch, opt, data, NULL, 0);
|
||||
|
||||
out:
|
||||
object_context_release(&ctx);
|
||||
}
|
||||
|
||||
struct object_cb_data {
|
||||
|
Reference in New Issue
Block a user