Fix memory leak in find_lib for some invalid inputs

This commit is contained in:
Emanuele Torre authored and Nico Williams committed 2023-08-26 17:17:29 -05:00
1 parent 2c3561810d
commit 6436f1e0f8
1 file changed
+6
+6
View File
@@ -136,16 +136,22 @@ static jv jv_basename(jv name) {
static jv find_lib(jq_state *jq, jv rel_path, jv search, const char *suffix, jv jq_origin, jv lib_origin) {
if (!jv_is_valid(rel_path)) {
jv_free(search);
jv_free(jq_origin);
jv_free(lib_origin);
return rel_path;
}
if (jv_get_kind(rel_path) != JV_KIND_STRING) {
jv_free(rel_path);
jv_free(search);
jv_free(jq_origin);
jv_free(lib_origin);
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);
jv_free(jq_origin);
jv_free(lib_origin);
return jv_invalid_with_msg(jv_string_fmt("Module search path must be an array"));
}