Skip to content

Commit 0f3a461

Browse files
Linus Arvergitster
authored andcommitted
trailer: free trailer_info _after_ all related usage
In de7c27a (trailer: use offsets for trailer_start/trailer_end, 2023-10-20), we started using trailer block offsets in trailer_info. In particular, we dropped the use of a separate stack variable "size_t trailer_end", in favor of accessing the new "trailer_block_end" member of trailer_info (as "info.trailer_block_end"). At that time, we forgot to also move the trailer_info_release(&info); line to be _after_ this new use of the trailer_info struct. Move it now. Note that even without this patch, we didn't have leaks or any other problems because trailer_info_release() only frees memory allocated on the heap. The "trailer_block_end" member was allocated on the stack back then (as it is now) so it was still safe to use for all this time. Reported-by: Junio C Hamano <[email protected]> Signed-off-by: Linus Arver <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent a54a84b commit 0f3a461

File tree

1 file changed

+1
-2
lines changed

1 file changed

+1
-2
lines changed

trailer.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1111,13 +1111,12 @@ void process_trailers(const char *file,
11111111
}
11121112

11131113
print_all(outfile, &head, opts);
1114-
11151114
free_all(&head);
1116-
trailer_info_release(&info);
11171115

11181116
/* Print the lines after the trailers as is */
11191117
if (!opts->only_trailers)
11201118
fwrite(sb.buf + info.trailer_block_end, 1, sb.len - info.trailer_block_end, outfile);
1119+
trailer_info_release(&info);
11211120

11221121
if (opts->in_place)
11231122
if (rename_tempfile(&trailers_tempfile, file))

0 commit comments

Comments
 (0)