Skip to content

Commit

Permalink
Defer heap variable initialisation after pledge
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
klemensn committed Oct 21, 2023
1 parent 03b724b commit eaf07ea
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -317,8 +317,8 @@ 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 */
jv ARGS;
jv program_arguments;

#ifdef HAVE_SETLOCALE
(void) setlocale(LC_ALL, "");
Expand All @@ -341,6 +341,9 @@ int main(int argc, char* argv[]) {

if (argc) progname = argv[0];

ARGS = jv_array();
program_arguments = jv_object();

jq = jq_init();
if (jq == NULL) {
perror("malloc");
Expand Down

0 comments on commit eaf07ea

Please sign in to comment.