You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

40 lines
1.4 KiB

  1. From 2e3dbb884199bba6cc07345f6d394f1ac53465ac Mon Sep 17 00:00:00 2001
  2. From: Muh Muhten <muh.muhten@gmail.com>
  3. Date: Tue, 19 Feb 2019 00:34:04 -0500
  4. Subject: [PATCH 4/9] Pass on the error message when rel_path is invalid
  5. "Module path must be a string" is not a useful error message when the
  6. reason the module path isn't a string is because the string it was got
  7. replaced with an invalid with an error message for some other reason.
  8. Also fixes a few memory leaks on early exits.
  9. ---
  10. src/linker.c | 16 +++++++++++++---
  11. 1 file changed, 13 insertions(+), 3 deletions(-)
  12. --- a/src/linker.c
  13. +++ b/src/linker.c
  14. @@ -138,10 +138,20 @@ static jv jv_basename(jv name) {
  15. // Asummes validated relative path to module
  16. static jv find_lib(jq_state *jq, jv rel_path, jv search, const char *suffix, jv jq_origin, jv lib_origin) {
  17. - if (jv_get_kind(search) != JV_KIND_ARRAY)
  18. - return jv_invalid_with_msg(jv_string_fmt("Module search path must be an array"));
  19. - if (jv_get_kind(rel_path) != JV_KIND_STRING)
  20. + if (!jv_is_valid(rel_path)) {
  21. + jv_free(search);
  22. + return rel_path;
  23. + }
  24. + if (jv_get_kind(rel_path) != JV_KIND_STRING) {
  25. + jv_free(rel_path);
  26. + jv_free(search);
  27. return jv_invalid_with_msg(jv_string_fmt("Module path must be a string"));
  28. + }
  29. + if (jv_get_kind(search) != JV_KIND_ARRAY) {
  30. + jv_free(rel_path);
  31. + jv_free(search);
  32. + return jv_invalid_with_msg(jv_string_fmt("Module search path must be an array"));
  33. + }
  34. struct stat st;
  35. int ret;