summaryrefslogtreecommitdiff
path: root/src/opt.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/opt.c')
-rw-r--r--src/opt.c11
1 files changed, 9 insertions, 2 deletions
diff --git a/src/opt.c b/src/opt.c
index 8efbf52..fe2bff3 100644
--- a/src/opt.c
+++ b/src/opt.c
@@ -758,6 +758,7 @@ EXPORT_SYMBOL int HX_getopt(const struct HXoption *table, int *argc,
out:
if (ret == HXOPT_ERR_SUCCESS) {
+ if (!(ps.flags & HXOPT_KEEP_ARGV)) {
const char **nvec = reinterpret_cast(const char **,
HXdeque_to_vec(ps.remaining, &argk));
if (nvec == NULL)
@@ -776,6 +777,10 @@ EXPORT_SYMBOL int HX_getopt(const struct HXoption *table, int *argc,
*argv = nvec;
if (argc != NULL)
*argc = argk;
+ /* pointers are owned by nvec/argv now */
+ HXdeque_free(ps.remaining);
+ ps.remaining = nullptr;
+ }
} else if (ret < 0) {
if (!(ps.flags & HXOPT_QUIET))
fprintf(stderr, "%s: %s\n", __func__, strerror(errno));
@@ -786,8 +791,8 @@ EXPORT_SYMBOL int HX_getopt(const struct HXoption *table, int *argc,
else if (ps.flags & HXOPT_USAGEONERR)
HX_getopt_usage(&ps.cbi, stderr);
}
-
- HXdeque_free(ps.remaining);
+ if (ps.remaining != nullptr)
+ HXdeque_genocide2(ps.remaining, free);
return ret;
out_errno:
@@ -1011,6 +1016,8 @@ EXPORT_SYMBOL int HX_shconfig_pv(const char **path, const char *file,
EXPORT_SYMBOL void HX_shconfig_free(const struct HXoption *table)
{
+ if (table == NULL)
+ return;
for (; table->ln != NULL; ++table) {
char **ptr = table->ptr;
if (table->type == HXTYPE_STRING &&