diff options
author | Klemens Nanni <kn@openbsd.org> | 2023-10-21 23:59:20 +0300 |
---|---|---|
committer | Nico Williams <nico@cryptonector.com> | 2023-10-21 23:30:36 -0500 |
commit | 7ab117a483e127006f30efa818a7a8281077ec72 (patch) | |
tree | 2849e59b0b0cabc7858c168691b27b9d66d34409 /src/main.c | |
parent | 77dcaf3fdc9a23c2a318da4f4a944143748e5961 (diff) |
Defer heap variable initialisation after pledge
Otherwise `AGRS` and `program_arguments` remain allocated/unfreed in the
early (extremely unlikely) pledge(2) failure case.
Move their allocation before jq_init(), the first case of jumping to
`out` where they are cleaned up, where it also seems to logically fit
better than above between function entry, locale setup and OpenBSD
specific pledge.
Diffstat (limited to 'src/main.c')
-rw-r--r-- | src/main.c | 5 |
1 files changed, 3 insertions, 2 deletions
@@ -317,8 +317,6 @@ int main(int argc, char* argv[]) { int last_result = -1; /* -1 = no result, 0=null or false, 1=true */ int badwrite; int options = 0; - jv ARGS = jv_array(); /* positional arguments */ - jv program_arguments = jv_object(); /* named arguments */ #ifdef HAVE_SETLOCALE (void) setlocale(LC_ALL, ""); @@ -339,6 +337,9 @@ int main(int argc, char* argv[]) { _setmode(fileno(stderr), _O_TEXT | _O_U8TEXT); #endif + jv ARGS = jv_array(); /* positional arguments */ + jv program_arguments = jv_object(); /* named arguments */ + if (argc) progname = argv[0]; jq = jq_init(); |