]> granicus.if.org Git - jq/commitdiff
Fix leak on error in strptime
authorNicolas Williams <nico@cryptonector.com>
Thu, 23 Nov 2017 07:51:22 +0000 (01:51 -0600)
committerNicolas Williams <nico@cryptonector.com>
Thu, 23 Nov 2017 07:51:22 +0000 (01:51 -0600)
src/builtin.c
tests/optional.test

index 23b91546b622a11975a5acdae172d8a7b3e9df7f..7323730212e6454fbb5f05625b09d8f87228c646 100644 (file)
@@ -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));
index fc37e60705b618a566c6135ca96ba9501f4b4da7..8e739d5d01653db60a0ef733c873f9a67737e885 100644 (file)
@@ -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