commit eaa483e7cb2f757f63882e6add0714c0f10b06df842f7a87658b4d2e8d1a6573 from: Mikhail Pchelin via: Stefan Sperling date: Sat Sep 26 20:12:13 2026 UTC plug a memory leak caused by duplicate ignore patterns When pattern in ignore file is repeated, RB_INSERT() will return pointer to already existing element, not inserting new one, in this case we leak the pattern pointer. Patch by Mikhail Pchelin commit - 5202bcb0ad315ef2e0b80d183118906724921094fbbea43bd892aef98fc50dd7 commit + eaa483e7cb2f757f63882e6add0714c0f10b06df842f7a87658b4d2e8d1a6573 blob - cd43af6f232741d02637e8dc2808ff3d8fc364083ce4687099a1be3fafdacf10 blob + f18707e09ce0efae0d1f7afb411360363da30d483e2f7e47ce24de4242af612b --- lib/worktree.c +++ lib/worktree.c @@ -3811,7 +3811,7 @@ static const struct got_error * read_ignores(struct got_pathlist_head *ignores, const char *path, FILE *f) { const struct got_error *err = NULL; - struct got_pathlist_entry *pe = NULL; + struct got_pathlist_entry *pe = NULL, *ipe = NULL; struct got_pathlist_head *ignorelist; char *line = NULL, *pattern, *dirpath = NULL; size_t linesize = 0; @@ -3843,7 +3843,13 @@ read_ignores(struct got_pathlist_head *ignores, const err = got_error_from_errno("asprintf"); goto done; } - err = got_pathlist_insert(NULL, ignorelist, pattern, NULL); + err = got_pathlist_insert(&ipe, ignorelist, pattern, NULL); + /* + * got_pathlist_insert() silently rejects duplicated pattern; + * free it. + */ + if (err || ipe == NULL) + free(pattern); if (err) goto done; }