Commit 94f719e
committed
optparse: fix segfault on optparse_reg_subcommand() failure
Problem: When an error in a subcommand definition causes the
registration of the subcommand to fail, liboptparse crashes due to
a double free.
This issue occurs whenever an optparse subcommand object is freed
before its parent. When the subcommand is unlinked from the parent
in optparse_destroy(), the zhash free function is called, which ends
up calling optparse_destroy() again.
If p->parent != NULL in optparse_destroy(), then the function is being
called directly on a child. After the call to zhash_delete(), return
immediately and let the destructor finish the rest of the cleanup.
Fixes #57311 parent ca942ab commit 94f719e
1 file changed
+12
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
697 | 697 | | |
698 | 698 | | |
699 | 699 | | |
700 | | - | |
| 700 | + | |
701 | 701 | | |
| 702 | + | |
| 703 | + | |
| 704 | + | |
| 705 | + | |
| 706 | + | |
| 707 | + | |
| 708 | + | |
| 709 | + | |
| 710 | + | |
| 711 | + | |
| 712 | + | |
702 | 713 | | |
703 | 714 | | |
704 | 715 | | |
| |||
0 commit comments