git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH v2 13/13] alloc: allow arbitrary repositories for alloc functions

From
Jeff King <peff@peff.net>
Date
May 8, 2018, 10:10 UTC
Message-ID
<20180508101022.GA17501@sigill.intra.peff.net>
In-Reply-To
<20180507225916.155236-14-sbeller@google.com>
On Mon, May 07, 2018 at 03:59:16PM -0700, Stefan Beller wrote:
Show 16 quoted lines
> @@ -501,9 +509,31 @@ void raw_object_store_clear(struct raw_object_store *o)
>  void parsed_object_pool_clear(struct parsed_object_pool *o)
> [...]
> +	for (i = 0; i < o->obj_hash_size; i++) {
> +		struct object *obj = o->obj_hash[i];
> +
> +		if (!obj)
> +			continue;
> +
> +		if (obj->type == OBJ_TREE) {
> +			free(((struct tree*)obj)->buffer);
> +		} else if (obj->type == OBJ_COMMIT) {
> +			free_commit_list(((struct commit*)obj)->parents);
> +			free(&((struct commit*)obj)->util);
> +		}
> +	}

Coverity complains about this final free(). I think the "&" is doing an incorrect extra level of indirection?

That said, I'm not sure if it is safe to blindly free the util field. We don't necessarily know what downstream code has pointed it to. It may not be allocated memory[1], or it may even be a more complicated data structure that has sub-components that need freeing[2].

In the long run, it may be worth trying to get rid of this util field completely, in favor of having callers use a commit_slab. That has better memory-ownership semantics, and it would save 8 bytes in struct commit.

[1] Grepping for "commit->util =", sequencer.c seems to assign pointers
    into other arrays, as well as the "(void *)1".
[2] Most assignments seem to be flex-structs, but blame.c assigns a
    linked list.
-Peff
Previous: Stefan BellerNext: Duy Nguyen
Message 44 of 95 in “object store: alloc”
  1. 00/13 object store: allocStefan Beller, May 1, 2018
  2. 01/13 repository: introduce object parser fieldStefan Beller, May 1, 2018
  3. Duy NguyenMay 2, 2018
  4. Stefan BellerMay 2, 2018
  5. Duy NguyenMay 2, 2018
  6. Jonathan TanMay 2, 2018
  7. 02/13 object: add repository argument to create_objectStefan Beller, May 1, 2018
  8. Eric SunshineMay 1, 2018
  9. 05/13 alloc: add repository argument to alloc_tree_nodeStefan Beller, May 1, 2018
  10. 07/13 alloc: add repository argument to alloc_tag_nodeStefan Beller, May 1, 2018
  11. 09/13 alloc: add repository argument to alloc_reportStefan Beller, May 1, 2018
  12. 10/13 alloc: add repository argument to alloc_commit_indexStefan Beller, May 1, 2018
  13. 12/13 object: allow create_object to handle arbitrary repositoriesStefan Beller, May 1, 2018
  14. Jonathan TanMay 2, 2018
  15. 13/13 alloc: allow arbitrary repositories for alloc functionsStefan Beller, May 1, 2018
  16. Duy NguyenMay 2, 2018
  17. Stefan BellerMay 3, 2018
  18. Duy NguyenMay 3, 2018
  19. Jonathan TanMay 2, 2018
  20. Stefan BellerMay 3, 2018
  21. Duy NguyenMay 3, 2018
  22. 11/13 object: allow grow_object_hash to handle arbitrary repositoriesStefan Beller, May 1, 2018
  23. 06/13 alloc: add repository argument to alloc_commit_nodeStefan Beller, May 1, 2018
  24. 08/13 alloc: add repository argument to alloc_object_nodeStefan Beller, May 1, 2018
  25. 03/13 object: add repository argument to grow_object_hashStefan Beller, May 1, 2018
  26. 04/13 alloc: add repository argument to alloc_blob_nodeStefan Beller, May 1, 2018
  27. Jonathan TanMay 2, 2018
  28. Duy NguyenMay 2, 2018
  29. Jameson MillerMay 2, 2018
  30. Duy NguyenMay 2, 2018
  31. Jameson MillerMay 2, 2018
  32. Stefan BellerMay 3, 2018
  33. Junio C HamanoMay 7, 2018
  34. Stefan BellerMay 7, 2018
  35. 00/13 object store: allocStefan Beller, May 7, 2018
  36. 02/13 object: add repository argument to create_objectStefan Beller, May 7, 2018
  37. 03/13 object: add repository argument to grow_object_hashStefan Beller, May 7, 2018
  38. 04/13 alloc: add repository argument to alloc_blob_nodeStefan Beller, May 7, 2018
  39. 08/13 alloc: add repository argument to alloc_object_nodeStefan Beller, May 7, 2018
  40. 10/13 alloc: add repository argument to alloc_commit_indexStefan Beller, May 7, 2018
  41. 11/13 object: allow grow_object_hash to handle arbitrary repositoriesStefan Beller, May 7, 2018
  42. 12/13 object: allow create_object to handle arbitrary repositoriesStefan Beller, May 7, 2018
  43. 13/13 alloc: allow arbitrary repositories for alloc functionsStefan Beller, May 7, 2018
  44. Jeff KingMay 8, 2018
  45. Duy NguyenMay 8, 2018
  46. Stefan BellerMay 8, 2018
  47. Jonathan TanMay 8, 2018
  48. 05/13 alloc: add repository argument to alloc_tree_nodeStefan Beller, May 7, 2018
  49. 06/13 alloc: add repository argument to alloc_commit_nodeStefan Beller, May 7, 2018
  50. 07/13 alloc: add repository argument to alloc_tag_nodeStefan Beller, May 7, 2018
  51. 09/13 alloc: add repository argument to alloc_reportStefan Beller, May 7, 2018
  52. 01/13 repository: introduce parsed objects fieldStefan Beller, May 7, 2018
  53. Jonathan TanMay 8, 2018
  54. 00/13 object store: allocStefan Beller, May 8, 2018
  55. 01/13 repository: introduce parsed objects fieldStefan Beller, May 8, 2018
  56. 02/13 object: add repository argument to create_objectStefan Beller, May 8, 2018
  57. 05/13 alloc: add repository argument to alloc_tree_nodeStefan Beller, May 8, 2018
  58. 07/13 alloc: add repository argument to alloc_tag_nodeStefan Beller, May 8, 2018
  59. 09/13 alloc: add repository argument to alloc_reportStefan Beller, May 8, 2018
  60. 10/13 alloc: add repository argument to alloc_commit_indexStefan Beller, May 8, 2018
  61. 11/13 object: allow grow_object_hash to handle arbitrary repositoriesStefan Beller, May 8, 2018
  62. 12/13 object: allow create_object to handle arbitrary repositoriesStefan Beller, May 8, 2018
  63. 13/13 alloc: allow arbitrary repositories for alloc functionsStefan Beller, May 8, 2018
  64. Jonathan TanMay 8, 2018
  65. Stefan BellerMay 8, 2018
  66. Duy NguyenMay 9, 2018
  67. Duy NguyenMay 9, 2018
  68. Stefan BellerMay 9, 2018
  69. Duy NguyenMay 10, 2018
  70. 08/13 alloc: add repository argument to alloc_object_nodeStefan Beller, May 8, 2018
  71. 03/13 object: add repository argument to grow_object_hashStefan Beller, May 8, 2018
  72. 04/13 alloc: add repository argument to alloc_blob_nodeStefan Beller, May 8, 2018
  73. 06/13 alloc: add repository argument to alloc_commit_nodeStefan Beller, May 8, 2018
  74. 00/13 object store: allocStefan Beller, May 10, 2018
  75. 01/13 repository: introduce parsed objects fieldStefan Beller, May 10, 2018
  76. 03/13 object: add repository argument to grow_object_hashStefan Beller, May 10, 2018
  77. 06/13 alloc: add repository argument to alloc_commit_nodeStefan Beller, May 10, 2018
  78. 08/13 alloc: add repository argument to alloc_object_nodeStefan Beller, May 10, 2018
  79. 10/13 alloc: add repository argument to alloc_commit_indexStefan Beller, May 10, 2018
  80. 12/13 object: allow create_object to handle arbitrary repositoriesStefan Beller, May 10, 2018
  81. 11/13 object: allow grow_object_hash to handle arbitrary repositoriesStefan Beller, May 10, 2018
  82. 13/13 alloc: allow arbitrary repositories for alloc functionsStefan Beller, May 10, 2018
  83. 05/13 alloc: add repository argument to alloc_tree_nodeStefan Beller, May 10, 2018
  84. 09/13 alloc: add repository argument to alloc_reportStefan Beller, May 10, 2018
  85. 07/13 alloc: add repository argument to alloc_tag_nodeStefan Beller, May 10, 2018
  86. 02/13 object: add repository argument to create_objectStefan Beller, May 10, 2018
  87. 04/13 alloc: add repository argument to alloc_blob_nodeStefan Beller, May 10, 2018
  88. Jonathan TanMay 10, 2018
  89. Stefan BellerMay 10, 2018
  90. Jonathan TanMay 10, 2018
  91. Stefan BellerMay 10, 2018
  92. alloc: allow arbitrary repositories for alloc functionsStefan Beller, May 11, 2018
  93. Eric SunshineMay 11, 2018
  94. alloc: allow arbitrary repositories for alloc functionsStefan Beller, May 15, 2018
  95. Junio C HamanoMay 16, 2018

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.