diff options
author | Muh Muhten <muh.muhten@gmail.com> | 2019-02-19 00:34:04 -0500 |
---|---|---|
committer | Nico Williams <nico@cryptonector.com> | 2019-02-20 19:16:18 -0600 |
commit | ff014824bc30424044658c9950d6e6d9c8fae73f (patch) | |
tree | 23dabf41a734cbc7e56d2384fec07562cd6cbb29 | |
parent | 8edf58a95fdebfba7b6a6145e2f58cdb4f3eb64c (diff) |
Pass on the error message when rel_path is invalid
"Module path must be a string" is not a useful error message when the
reason the module path isn't a string is because the string it was got
replaced with an invalid with an error message for some other reason.
Also fixes a few memory leaks on early exits.
-rw-r--r-- | src/linker.c | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/src/linker.c b/src/linker.c index 365480b0..c983832c 100644 --- a/src/linker.c +++ b/src/linker.c @@ -138,10 +138,20 @@ static jv jv_basename(jv name) { // Asummes validated relative path to module static jv find_lib(jq_state *jq, jv rel_path, jv search, const char *suffix, jv jq_origin, jv lib_origin) { - if (jv_get_kind(search) != JV_KIND_ARRAY) - return jv_invalid_with_msg(jv_string_fmt("Module search path must be an array")); - if (jv_get_kind(rel_path) != JV_KIND_STRING) + if (!jv_is_valid(rel_path)) { + jv_free(search); + return rel_path; + } + if (jv_get_kind(rel_path) != JV_KIND_STRING) { + jv_free(rel_path); + jv_free(search); return jv_invalid_with_msg(jv_string_fmt("Module path must be a string")); + } + if (jv_get_kind(search) != JV_KIND_ARRAY) { + jv_free(rel_path); + jv_free(search); + return jv_invalid_with_msg(jv_string_fmt("Module search path must be an array")); + } struct stat st; int ret; |