From: Junio C Hamano <gitster@pobox.com>
To: Jonathon Mah <jmah@me.com>
Cc: git@vger.kernel.org
Subject: Re: [PATCH] parse_object: clear "parsed" when freeing buffers
Date: Wed, 23 Jan 2013 14:19:05 -0800 [thread overview]
Message-ID: <7vsj5rfspy.fsf@alter.siamese.dyndns.org> (raw)
In-Reply-To: <8988071A-1DF3-463E-8AF9-AE4EA200D786@me.com> (Jonathon Mah's message of "Wed, 23 Jan 2013 13:25:04 -0800")
Jonathon Mah <jmah@me.com> writes:
> Add a new function "free_object_buffer", which marks the object as
> un-parsed and frees the buffer. Only trees and commits have buffers;
> other types are not affected. If the tree or commit buffer is already
> NULL, the "parsed" flag is still cleared so callers can control the free
> themselves (index-pack.c uses this).
>
> Several areas of code would free buffers for object structs that
> contained them ("struct tree" and "struct commit"), but without clearing
> the "parsed" flag. parse_object would clear the flag for "struct tree",
> but commits would remain in an invalid state (marked as parsed but with
> a NULL buffer). Because the objects are uniqued (ccdc6037fee), the
> invalid objects stay around and can lead to bad behavior.
>
> In particular, running pickaxe on all refs in a repository with a cached
> textconv could segfault. If the textconv cache ref was evaluated first
> by cmd_log_walk, a subsequent notes_cache_match_validity call would
> dereference NULL.
Conceptually this is a right thing to do, but it is unclear why this
conversion is safe in the existing code.
A codepath that used to free() and assign NULL to a buffer without
resetting .parsed would have assumed that it can find out the parsed
properties of the object (e.g. .parents) without re-parsing the
object, and much more importantly, the modifications made by that
codepath will not be clobbered by later call to parse_object().
IIRC, revision traversal machinery rewrites commit->parents but
discards buffer when it knows that the log message is not needed
(save_commit_buffer controls this behaviour). I do not offhand know
if there are other instances of existing code that depend on the
current behaviour, but have you audited all the codepaths that are
affected by this patch and codepaths that work on objects this patch
unmarks their .parsed field will not have such a problem?
next prev parent reply other threads:[~2013-01-23 22:19 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-01-23 21:25 [PATCH] parse_object: clear "parsed" when freeing buffers Jonathon Mah
2013-01-23 22:19 ` Junio C Hamano [this message]
2013-01-23 23:36 ` Jonathon Mah
2013-01-24 0:25 ` Junio C Hamano
2013-01-24 6:33 ` Jeff King
2013-01-24 16:51 ` Junio C Hamano
2013-01-24 7:07 ` Jeff King
2013-01-24 21:16 ` Jonathon Mah
2013-01-24 23:27 ` Jonathon Mah
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=7vsj5rfspy.fsf@alter.siamese.dyndns.org \
--to=gitster@pobox.com \
--cc=git@vger.kernel.org \
--cc=jmah@me.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).