From 18879fb99367924cd76d402e841155bf73c8afb3 Mon Sep 17 00:00:00 2001 From: Nicolas Williams Date: Thu, 23 Nov 2017 01:51:22 -0600 Subject: Fix leak on error in strptime --- src/builtin.c | 5 ++++- tests/optional.test | 1 + 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/builtin.c b/src/builtin.c index 23b91546..73237302 100644 --- a/src/builtin.c +++ b/src/builtin.c @@ -1280,8 +1280,11 @@ static void set_tm_yday(struct tm *tm) { #ifdef HAVE_STRPTIME static jv f_strptime(jq_state *jq, jv a, jv b) { - if (jv_get_kind(a) != JV_KIND_STRING || jv_get_kind(b) != JV_KIND_STRING) + if (jv_get_kind(a) != JV_KIND_STRING || jv_get_kind(b) != JV_KIND_STRING) { + jv_free(a); + jv_free(b); return jv_invalid_with_msg(jv_string("strptime/1 requires string inputs and arguments")); + } struct tm tm; memset(&tm, 0, sizeof(tm)); diff --git a/tests/optional.test b/tests/optional.test index fc37e607..8e739d5d 100644 --- a/tests/optional.test +++ b/tests/optional.test @@ -2,6 +2,7 @@ # strptime() is not available on mingw/WIN32 [strptime("%Y-%m-%dT%H:%M:%SZ")|(.,mktime)] +"2015-03-05T23:51:47Z" [[2015,2,5,23,51,47,4,63],1425599507] # Check day-of-week and day of year computations -- cgit v1.2.3