summaryrefslogtreecommitdiff
path: root/diffcore-order.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2024-10-02 07:46:25 -0700
committerJunio C Hamano <gitster@pobox.com>2024-10-02 07:46:26 -0700
commit365529e1ea19b44a7a253b780f3ae3a1cb2f081f (patch)
tree5a34837f74d165858246b1dd9706b926d7a998e5 /diffcore-order.c
parent9293a931868f21029baf55935f2f092c3f06415f (diff)
parent12dfc2475ce4808df696fb67fc71a66793f78f06 (diff)
Merge branch 'ps/leakfixes-part-7'
More leak-fixes. * ps/leakfixes-part-7: (23 commits) diffcore-break: fix leaking filespecs when merging broken pairs revision: fix leaking parents when simplifying commits builtin/maintenance: fix leak in `get_schedule_cmd()` builtin/maintenance: fix leaking config string promisor-remote: fix leaking partial clone filter grep: fix leaking grep pattern submodule: fix leaking submodule ODB paths trace2: destroy context stored in thread-local storage builtin/difftool: plug several trivial memory leaks builtin/repack: fix leaking configuration diffcore-order: fix leaking buffer when parsing orderfiles parse-options: free previous value of `OPTION_FILENAME` diff: fix leaking orderfile option builtin/pull: fix leaking "ff" option dir: fix off by one errors for ignored and untracked entries builtin/submodule--helper: fix leaking remote ref on errors t/helper: fix leaking subrepo in nested submodule config helper builtin/submodule--helper: fix leaking error buffer builtin/submodule--helper: clear child process when not running it submodule: fix leaking update strategy ...
Diffstat (limited to 'diffcore-order.c')
-rw-r--r--diffcore-order.c19
1 files changed, 7 insertions, 12 deletions
diff --git a/diffcore-order.c b/diffcore-order.c
index e7d20ebd2d..912513d3e6 100644
--- a/diffcore-order.c
+++ b/diffcore-order.c
@@ -14,8 +14,7 @@ static void prepare_order(const char *orderfile)
{
int cnt, pass;
struct strbuf sb = STRBUF_INIT;
- void *map;
- char *cp, *endp;
+ const char *cp, *endp;
ssize_t sz;
if (order)
@@ -24,14 +23,13 @@ static void prepare_order(const char *orderfile)
sz = strbuf_read_file(&sb, orderfile, 0);
if (sz < 0)
die_errno(_("failed to read orderfile '%s'"), orderfile);
- map = strbuf_detach(&sb, NULL);
- endp = (char *) map + sz;
+ endp = sb.buf + sz;
for (pass = 0; pass < 2; pass++) {
cnt = 0;
- cp = map;
+ cp = sb.buf;
while (cp < endp) {
- char *ep;
+ const char *ep;
for (ep = cp; ep < endp && *ep != '\n'; ep++)
;
/* cp to ep has one line */
@@ -40,12 +38,7 @@ static void prepare_order(const char *orderfile)
else if (pass == 0)
cnt++;
else {
- if (*ep == '\n') {
- *ep = 0;
- order[cnt] = cp;
- } else {
- order[cnt] = xmemdupz(cp, ep - cp);
- }
+ order[cnt] = xmemdupz(cp, ep - cp);
cnt++;
}
if (ep < endp)
@@ -57,6 +50,8 @@ static void prepare_order(const char *orderfile)
ALLOC_ARRAY(order, cnt);
}
}
+
+ strbuf_release(&sb);
}
static int match_order(const char *path)