[fdplane] constify args/env, kill unit test memory leaks

This commit is contained in:
nick black 2021-11-11 10:08:03 -05:00
parent d51318f58c
commit f377e30300
No known key found for this signature in database
GPG Key ID: 5F43400C21CBFACC
3 changed files with 15 additions and 13 deletions

View File

@ -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)));

View File

@ -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){

View File

@ -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;