git/list[1] front-page[2] threads[3] people[4] search[5] about
wed 2026-10-07 18:08 UTC

[PATCH v5 1/4] strbuf: pass correct alloc to strbuf_attach() in strbuf_reencode()

From
Vaidas Pilkauskas via GitGitGadget <gitgitgadget@gmail.com>
Date
Feb 23, 2026, 14:20 UTC
Message-ID
<7ec2d6644785827c047a55a99b213468583c6c1a.1771856405.git.gitgitgadget@gmail.com>
In-Reply-To
<pull.2008.v5.git.1771856405.gitgitgadget@gmail.com>
From: Vaidas Pilkauskas <vaidas.pilkauskas@shopify.com>

reencode_string_len() allocates len+1 bytes (including the NUL) and returns the string length in len. strbuf_reencode() was calling strbuf_attach(sb, out, len, len), so alloc was one byte too small.

strbuf_attach() then calls strbuf_grow(sb, 0). With alloc < len+1, ALLOC_GROW always reallocates, so we reallocated immediately after attach even when the strbuf was not extended further. Pass len+1 as the alloc argument so the existing buffer is reused and the reallocation is avoided.

Signed-off-by: Vaidas Pilkauskas <vaidas.pilkauskas@shopify.com>
---
 strbuf.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/strbuf.c b/strbuf.c
index 3939863cf3..3e04addc22 100644
--- a/strbuf.c
+++ b/strbuf.c
@@ -168,7 +168,7 @@ int strbuf_reencode(struct strbuf *sb, const char *from, const char *to)
 	if (!out)
 		return -1;
 
-	strbuf_attach(sb, out, len, len);
+	strbuf_attach(sb, out, len, len + 1);
 	return 0;
 }
 
-- 
gitgitgadget
Previous: Vaidas Pilkauskas via GitGitGadgetNext: Vaidas Pilkauskas via GitGitGadget
Message 32 of 49 in “http: add support for HTTP 429 rate limit retries”
  1. 0/3 http: add support for HTTP 429 rate limit retriesVaidas Pilkauskas via GitGitGadget, Nov 26, 2025
  2. 1/3 http: add support for HTTP 429 rate limit retriesVaidas Pilkauskas via GitGitGadget, Nov 26, 2025
  3. 2/3 remote-curl: fix memory leak in show_http_message()Vaidas Pilkauskas via GitGitGadget, Nov 26, 2025
  4. 3/3 http: add trace2 logging for retry operationsVaidas Pilkauskas via GitGitGadget, Nov 26, 2025
  5. Taylor BlauDec 9, 2025
  6. Taylor BlauDec 9, 2025
  7. Vaidas PilkauskasDec 12, 2025
  8. 0/2 http: add support for HTTP 429 rate limit retriesVaidas Pilkauskas via GitGitGadget, Dec 18, 2025
  9. 1/2 http: add support for HTTP 429 rate limit retriesVaidas Pilkauskas via GitGitGadget, Dec 18, 2025
  10. 2/2 http: add trace2 logging for retry operationsVaidas Pilkauskas via GitGitGadget, Dec 18, 2025
  11. Taylor BlauFeb 11, 2026
  12. Taylor BlauFeb 11, 2026
  13. Jeff KingFeb 11, 2026
  14. Vaidas PilkauskasFeb 13, 2026
  15. Vaidas PilkauskasFeb 13, 2026
  16. Jeff KingFeb 15, 2026
  17. 0/3 http: add support for HTTP 429 rate limit retriesVaidas Pilkauskas via GitGitGadget, Feb 17, 2026
  18. 1/3 strbuf: fix incorrect alloc size in strbuf_reencode()Vaidas Pilkauskas via GitGitGadget, Feb 17, 2026
  19. 2/3 remote-curl: introduce show_http_message_fatal() helperVaidas Pilkauskas via GitGitGadget, Feb 17, 2026
  20. 3/3 http: add support for HTTP 429 rate limit retriesVaidas Pilkauskas via GitGitGadget, Feb 17, 2026
  21. Junio C HamanoFeb 17, 2026
  22. Vaidas PilkauskasFeb 18, 2026
  23. 0/5 http: add support for HTTP 429 rate limit retriesVaidas Pilkauskas via GitGitGadget, Feb 18, 2026
  24. 1/5 strbuf: pass correct alloc to strbuf_attach() in strbuf_reencode()Vaidas Pilkauskas via GitGitGadget, Feb 18, 2026
  25. 2/5 strbuf_attach: fix all call sites to pass correct allocVaidas Pilkauskas via GitGitGadget, Feb 18, 2026
  26. 3/5 strbuf: replace strbuf_grow() in strbuf_attach() with BUG() checkVaidas Pilkauskas via GitGitGadget, Feb 18, 2026
  27. 4/5 remote-curl: introduce show_http_message_fatal() helperVaidas Pilkauskas via GitGitGadget, Feb 18, 2026
  28. 5/5 http: add support for HTTP 429 rate limit retriesVaidas Pilkauskas via GitGitGadget, Feb 18, 2026
  29. Junio C HamanoFeb 20, 2026
  30. Vaidas PilkauskasFeb 23, 2026
  31. 0/4 http: add support for HTTP 429 rate limit retriesVaidas Pilkauskas via GitGitGadget, Feb 23, 2026
  32. 1/4 strbuf: pass correct alloc to strbuf_attach() in strbuf_reencode()Vaidas Pilkauskas via GitGitGadget, Feb 23, 2026
  33. 2/4 strbuf_attach: fix call sites to pass correct allocVaidas Pilkauskas via GitGitGadget, Feb 23, 2026
  34. 3/4 remote-curl: introduce show_http_message_fatal() helperVaidas Pilkauskas via GitGitGadget, Feb 23, 2026
  35. 4/4 http: add support for HTTP 429 rate limit retriesVaidas Pilkauskas via GitGitGadget, Feb 23, 2026
  36. Junio C HamanoFeb 24, 2026
  37. Junio C HamanoMar 9, 2026
  38. Jeff KingMar 10, 2026
  39. Jeff KingMar 10, 2026
  40. Jeff KingMar 10, 2026
  41. Junio C HamanoMar 10, 2026
  42. 0/3 http: add support for HTTP 429 rate limit retriesVaidas Pilkauskas via GitGitGadget, Mar 17, 2026
  43. 2/3 strbuf_attach: fix call sites to pass correct allocVaidas Pilkauskas via GitGitGadget, Mar 17, 2026
  44. 3/3 http: add support for HTTP 429 rate limit retriesVaidas Pilkauskas via GitGitGadget, Mar 17, 2026
  45. 1/3 strbuf: pass correct alloc to strbuf_attach() in strbuf_reencode()Vaidas Pilkauskas via GitGitGadget, Mar 17, 2026
  46. Taylor BlauMar 21, 2026
  47. Taylor BlauMar 21, 2026
  48. Junio C HamanoMar 21, 2026
  49. Vaidas PilkauskasMar 23, 2026

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.