get_sha1_oneline: fix lifespan rule of temp_commit_buffer variable

This is trying to free only what we ourselves read (as opposed to what
we borrowed from commit->buffer) but do so lazily only to work around
the fact that the code has many irregular exit points, and doing it right
makes it necessary to call free() from many different places in the loop.

Rewrite the structure of the code inside the loop so that the variable
has to live within a single iteration, ever.  This should make the logic
easier to follow as well.

Also we didn't free a temporary commit list we kept to hold the original
set of commits.  Free it.

Noticed-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 file changed
tree: 8138ba4200c39c7c22ed535c11bcd2cf57029a3b
  1. block-sha1/
  2. builtin/
  3. compat/
  4. contrib/
  5. Documentation/
  6. git-gui/
  7. git_remote_helpers/
  8. gitk-git/
  9. gitweb/
  10. perl/
  11. ppc/
  12. t/
  13. templates/
  14. vcs-svn/
  15. xdiff/
  16. .gitattributes
  17. .gitignore
  18. .mailmap
  19. abspath.c
  20. aclocal.m4
  21. advice.c
  22. advice.h
  23. alias.c
  24. alloc.c
  25. archive-tar.c
  26. archive-zip.c
  27. archive.c
  28. archive.h
  29. attr.c
  30. attr.h
  31. base85.c
  32. bisect.c
  33. bisect.h
  34. blob.c
  35. blob.h
  36. branch.c
  37. branch.h
  38. builtin.h
  39. bundle.c
  40. bundle.h
  41. cache-tree.c
  42. cache-tree.h
  43. cache.h
  44. check-builtins.sh
  45. check-racy.c
  46. check_bindir
  47. color.c
  48. color.h
  49. combine-diff.c
  50. command-list.txt
  51. commit.c
  52. commit.h
  53. config.c
  54. config.mak.in
  55. configure.ac
  56. connect.c
  57. convert.c
  58. copy.c
  59. COPYING
  60. csum-file.c
  61. csum-file.h
  62. ctype.c
  63. daemon.c
  64. date.c
  65. decorate.c
  66. decorate.h
  67. delta.h
  68. diff-delta.c
  69. diff-lib.c
  70. diff-no-index.c
  71. diff.c
  72. diff.h
  73. diffcore-break.c
  74. diffcore-delta.c
  75. diffcore-order.c
  76. diffcore-pickaxe.c
  77. diffcore-rename.c
  78. diffcore.h
  79. dir.c
  80. dir.h
  81. editor.c
  82. entry.c
  83. environment.c
  84. exec_cmd.c
  85. exec_cmd.h
  86. fast-import.c
  87. fetch-pack.h
  88. fixup-builtins
  89. fsck.c
  90. fsck.h
  91. generate-cmdlist.sh
  92. git-add--interactive.perl
  93. git-am.sh
  94. git-archimport.perl
  95. git-bisect.sh
  96. git-compat-util.h
  97. git-cvsexportcommit.perl
  98. git-cvsimport.perl
  99. git-cvsserver.perl
  100. git-difftool--helper.sh
  101. git-difftool.perl
  102. git-filter-branch.sh
  103. git-instaweb.sh
  104. git-lost-found.sh
  105. git-merge-octopus.sh
  106. git-merge-one-file.sh
  107. git-merge-resolve.sh
  108. git-mergetool--lib.sh
  109. git-mergetool.sh
  110. git-parse-remote.sh
  111. git-pull.sh
  112. git-quiltimport.sh
  113. git-rebase--interactive.sh
  114. git-rebase.sh
  115. git-relink.perl
  116. git-remote-testgit.py
  117. git-repack.sh
  118. git-request-pull.sh
  119. git-send-email.perl
  120. git-sh-setup.sh
  121. git-stash.sh
  122. git-submodule.sh
  123. git-svn.perl
  124. GIT-VERSION-GEN
  125. git-web--browse.sh
  126. git.c
  127. git.spec.in
  128. graph.c
  129. graph.h
  130. grep.c
  131. grep.h
  132. hash.c
  133. hash.h
  134. help.c
  135. help.h
  136. hex.c
  137. http-backend.c
  138. http-fetch.c
  139. http-push.c
  140. http-walker.c
  141. http.c
  142. http.h
  143. ident.c
  144. imap-send.c
  145. INSTALL
  146. levenshtein.c
  147. levenshtein.h
  148. list-objects.c
  149. list-objects.h
  150. ll-merge.c
  151. ll-merge.h
  152. lockfile.c
  153. log-tree.c
  154. log-tree.h
  155. mailmap.c
  156. mailmap.h
  157. Makefile
  158. match-trees.c
  159. merge-file.c
  160. merge-recursive.c
  161. merge-recursive.h
  162. name-hash.c
  163. notes-cache.c
  164. notes-cache.h
  165. notes-merge.c
  166. notes-merge.h
  167. notes.c
  168. notes.h
  169. object.c
  170. object.h
  171. pack-check.c
  172. pack-refs.c
  173. pack-refs.h
  174. pack-revindex.c
  175. pack-revindex.h
  176. pack-write.c
  177. pack.h
  178. pager.c
  179. parse-options.c
  180. parse-options.h
  181. patch-delta.c
  182. patch-ids.c
  183. patch-ids.h
  184. path.c
  185. pkt-line.c
  186. pkt-line.h
  187. preload-index.c
  188. pretty.c
  189. progress.c
  190. progress.h
  191. quote.c
  192. quote.h
  193. reachable.c
  194. reachable.h
  195. read-cache.c
  196. README
  197. reflog-walk.c
  198. reflog-walk.h
  199. refs.c
  200. refs.h
  201. remote-curl.c
  202. remote.c
  203. remote.h
  204. replace_object.c
  205. rerere.c
  206. rerere.h
  207. resolve-undo.c
  208. resolve-undo.h
  209. revision.c
  210. revision.h
  211. run-command.c
  212. run-command.h
  213. send-pack.h
  214. server-info.c
  215. setup.c
  216. sha1-lookup.c
  217. sha1-lookup.h
  218. sha1_file.c
  219. sha1_name.c
  220. shallow.c
  221. shell.c
  222. shortlog.h
  223. show-index.c
  224. sideband.c
  225. sideband.h
  226. sigchain.c
  227. sigchain.h
  228. strbuf.c
  229. strbuf.h
  230. string-list.c
  231. string-list.h
  232. submodule.c
  233. submodule.h
  234. symlinks.c
  235. tag.c
  236. tag.h
  237. tar.h
  238. test-chmtime.c
  239. test-ctype.c
  240. test-date.c
  241. test-delta.c
  242. test-dump-cache-tree.c
  243. test-genrandom.c
  244. test-index-version.c
  245. test-line-buffer.c
  246. test-match-trees.c
  247. test-obj-pool.c
  248. test-parse-options.c
  249. test-path-utils.c
  250. test-run-command.c
  251. test-sha1.c
  252. test-sha1.sh
  253. test-sigchain.c
  254. test-string-pool.c
  255. test-svn-fe.c
  256. test-treap.c
  257. thread-utils.c
  258. thread-utils.h
  259. trace.c
  260. transport-helper.c
  261. transport.c
  262. transport.h
  263. tree-diff.c
  264. tree-walk.c
  265. tree-walk.h
  266. tree.c
  267. tree.h
  268. unimplemented.sh
  269. unpack-trees.c
  270. unpack-trees.h
  271. upload-pack.c
  272. url.c
  273. url.h
  274. usage.c
  275. userdiff.c
  276. userdiff.h
  277. utf8.c
  278. utf8.h
  279. walker.c
  280. walker.h
  281. wrap-for-bin.sh
  282. wrapper.c
  283. write_or_die.c
  284. ws.c
  285. wt-status.c
  286. wt-status.h
  287. xdiff-interface.c
  288. xdiff-interface.h
  289. zlib.c