From f377e303008f4fd08577f44798a919a59ab98be6 Mon Sep 17 00:00:00 2001 From: nick black Date: Thu, 11 Nov 2021 10:08:03 -0500 Subject: [PATCH] [fdplane] constify args/env, kill unit test memory leaks --- include/notcurses/notcurses.h | 7 ++++--- src/lib/fd.c | 13 +++++++------ src/tests/fds.cpp | 8 ++++---- 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/include/notcurses/notcurses.h b/include/notcurses/notcurses.h index 73297ce61..10eca3505 100644 --- a/include/notcurses/notcurses.h +++ b/include/notcurses/notcurses.h @@ -4211,17 +4211,18 @@ typedef struct ncsubproc_options { // see exec(2). p-types use $PATH. e-type passes environment vars. API ALLOC struct ncsubproc* ncsubproc_createv(struct ncplane* n, const ncsubproc_options* opts, - const char* bin, char* const arg[], + const char* bin, const char* const arg[], ncfdplane_callback cbfxn, ncfdplane_done_cb donecbfxn) __attribute__ ((nonnull (1))); API ALLOC struct ncsubproc* ncsubproc_createvp(struct ncplane* n, const ncsubproc_options* opts, - const char* bin, char* const arg[], + const char* bin, const char* const arg[], ncfdplane_callback cbfxn, ncfdplane_done_cb donecbfxn) __attribute__ ((nonnull (1))); API ALLOC struct ncsubproc* ncsubproc_createvpe(struct ncplane* n, const ncsubproc_options* opts, - const char* bin, char* const arg[], char* const env[], + const char* bin, const char* const arg[], + const char* const env[], ncfdplane_callback cbfxn, ncfdplane_done_cb donecbfxn) __attribute__ ((nonnull (1))); diff --git a/src/lib/fd.c b/src/lib/fd.c index 965c83679..92ad7f71b 100644 --- a/src/lib/fd.c +++ b/src/lib/fd.c @@ -378,21 +378,22 @@ ncexecvpe(ncplane* n, const ncsubproc_options* opts, unsigned usepath, } ncsubproc* ncsubproc_createv(ncplane* n, const ncsubproc_options* opts, - const char* bin, char* const arg[], + const char* bin, const char* const arg[], ncfdplane_callback cbfxn, ncfdplane_done_cb donecbfxn){ - return ncexecvpe(n, opts, 0, bin, arg, NULL, cbfxn, donecbfxn); + return ncexecvpe(n, opts, 0, bin, (char* const *)arg, NULL, cbfxn, donecbfxn); } ncsubproc* ncsubproc_createvp(ncplane* n, const ncsubproc_options* opts, - const char* bin, char* const arg[], + const char* bin, const char* const arg[], ncfdplane_callback cbfxn, ncfdplane_done_cb donecbfxn){ - return ncexecvpe(n, opts, 1, bin, arg, NULL, cbfxn, donecbfxn); + return ncexecvpe(n, opts, 1, bin, (char* const *)arg, NULL, cbfxn, donecbfxn); } ncsubproc* ncsubproc_createvpe(ncplane* n, const ncsubproc_options* opts, - const char* bin, char* const arg[], char* const env[], + const char* bin, const char* const arg[], + const char* const env[], ncfdplane_callback cbfxn, ncfdplane_done_cb donecbfxn){ - return ncexecvpe(n, opts, 1, bin, arg, env, cbfxn, donecbfxn); + return ncexecvpe(n, opts, 1, bin, (char* const *)arg, (char* const*)env, cbfxn, donecbfxn); } int ncsubproc_destroy(ncsubproc* n){ diff --git a/src/tests/fds.cpp b/src/tests/fds.cpp index c6888ae89..1daa73517 100644 --- a/src/tests/fds.cpp +++ b/src/tests/fds.cpp @@ -97,7 +97,7 @@ TEST_CASE("FdsAndSubprocs" /* SUBCASE("SubprocDestroyCmdExecFails") { - char * const argv[] = { strdup("/should-not-exist"), nullptr, }; + char * const argv[] = { "/should-not-exist", nullptr, }; bool outofline_cancelled = false; ncsubproc_options opts{}; opts.curry = &outofline_cancelled; @@ -116,7 +116,7 @@ TEST_CASE("FdsAndSubprocs" */ SUBCASE("SubprocDestroyCmdSucceeds") { - char * const argv[] = { strdup("/bin/cat"), strdup("/dev/null"), nullptr, }; + char const * const argv[] = { "/bin/cat", "/dev/null", nullptr, }; bool outofline_cancelled = false; ncsubproc_options opts{}; opts.curry = &outofline_cancelled; @@ -135,7 +135,7 @@ TEST_CASE("FdsAndSubprocs" // assuming the path /dev/nope doesn't exist, cat ought be successfully // launched (fork() and exec() both succeed), but then immediately fail. SUBCASE("SubprocDestroyCmdFailed") { - char * const argv[] = { strdup("/bin/cat"), strdup("/dev/nope"), nullptr, }; + char const * const argv[] = { "/bin/cat", "/dev/nope", nullptr, }; bool outofline_cancelled = false; ncsubproc_options opts{}; opts.curry = &outofline_cancelled; @@ -152,7 +152,7 @@ TEST_CASE("FdsAndSubprocs" } SUBCASE("SubprocDestroyCmdHung") { - char * const argv[] = { strdup("/bin/cat"), nullptr, }; + char const * const argv[] = { "/bin/cat", nullptr, }; bool outofline_cancelled = false; ncsubproc_options opts{}; opts.curry = &outofline_cancelled;