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
@ -1757,6 +1757,11 @@ int strbuf_check_branch_ref(struct strbuf *sb, const char *name)
|
||||
return check_refname_format(sb->buf, 0);
|
||||
}
|
||||
|
||||
void object_context_release(struct object_context *ctx)
|
||||
{
|
||||
free(ctx->path);
|
||||
}
|
||||
|
||||
/*
|
||||
* This is like "get_oid_basic()", except it allows "object ID expressions",
|
||||
* notably "xyz^" for "parent of xyz"
|
||||
@ -1764,7 +1769,9 @@ int strbuf_check_branch_ref(struct strbuf *sb, const char *name)
|
||||
int repo_get_oid(struct repository *r, const char *name, struct object_id *oid)
|
||||
{
|
||||
struct object_context unused;
|
||||
return get_oid_with_context(r, name, 0, oid, &unused);
|
||||
int ret = get_oid_with_context(r, name, 0, oid, &unused);
|
||||
object_context_release(&unused);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
@ -1802,8 +1809,10 @@ int repo_get_oid_committish(struct repository *r,
|
||||
struct object_id *oid)
|
||||
{
|
||||
struct object_context unused;
|
||||
return get_oid_with_context(r, name, GET_OID_COMMITTISH,
|
||||
oid, &unused);
|
||||
int ret = get_oid_with_context(r, name, GET_OID_COMMITTISH,
|
||||
oid, &unused);
|
||||
object_context_release(&unused);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int repo_get_oid_treeish(struct repository *r,
|
||||
@ -1811,8 +1820,10 @@ int repo_get_oid_treeish(struct repository *r,
|
||||
struct object_id *oid)
|
||||
{
|
||||
struct object_context unused;
|
||||
return get_oid_with_context(r, name, GET_OID_TREEISH,
|
||||
oid, &unused);
|
||||
int ret = get_oid_with_context(r, name, GET_OID_TREEISH,
|
||||
oid, &unused);
|
||||
object_context_release(&unused);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int repo_get_oid_commit(struct repository *r,
|
||||
@ -1820,8 +1831,10 @@ int repo_get_oid_commit(struct repository *r,
|
||||
struct object_id *oid)
|
||||
{
|
||||
struct object_context unused;
|
||||
return get_oid_with_context(r, name, GET_OID_COMMIT,
|
||||
oid, &unused);
|
||||
int ret = get_oid_with_context(r, name, GET_OID_COMMIT,
|
||||
oid, &unused);
|
||||
object_context_release(&unused);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int repo_get_oid_tree(struct repository *r,
|
||||
@ -1829,8 +1842,10 @@ int repo_get_oid_tree(struct repository *r,
|
||||
struct object_id *oid)
|
||||
{
|
||||
struct object_context unused;
|
||||
return get_oid_with_context(r, name, GET_OID_TREE,
|
||||
oid, &unused);
|
||||
int ret = get_oid_with_context(r, name, GET_OID_TREE,
|
||||
oid, &unused);
|
||||
object_context_release(&unused);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int repo_get_oid_blob(struct repository *r,
|
||||
@ -1838,8 +1853,10 @@ int repo_get_oid_blob(struct repository *r,
|
||||
struct object_id *oid)
|
||||
{
|
||||
struct object_context unused;
|
||||
return get_oid_with_context(r, name, GET_OID_BLOB,
|
||||
oid, &unused);
|
||||
int ret = get_oid_with_context(r, name, GET_OID_BLOB,
|
||||
oid, &unused);
|
||||
object_context_release(&unused);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Must be called only when object_name:filename doesn't exist. */
|
||||
@ -2117,6 +2134,7 @@ void maybe_die_on_misspelt_object_name(struct repository *r,
|
||||
struct object_id oid;
|
||||
get_oid_with_context_1(r, name, GET_OID_ONLY_TO_DIE | GET_OID_QUIETLY,
|
||||
prefix, &oid, &oc);
|
||||
object_context_release(&oc);
|
||||
}
|
||||
|
||||
enum get_oid_result get_oid_with_context(struct repository *repo,
|
||||
|
Reference in New Issue
Block a user