]> granicus.if.org Git - jq/commitdiff
Make sure to free in jv_string_indexes 1818/head
authorMuh Muhten <muh.muhten@gmail.com>
Sat, 9 Feb 2019 22:17:59 +0000 (17:17 -0500)
committerMuh Muhten <muh.muhten@gmail.com>
Sat, 9 Feb 2019 22:17:59 +0000 (17:17 -0500)
src/jv.c

index b3fcd5e3892c1ed8afc3dc0330e629b3eceb81db..06b4e6a29511910ce5f93bda82f43f4d177f9d54 100644 (file)
--- a/src/jv.c
+++ b/src/jv.c
@@ -658,12 +658,12 @@ jv jv_string_indexes(jv j, jv k) {
   int idxlen = jv_string_length_bytes(jv_copy(k));
   jv a = jv_array();
 
-  if (idxlen == 0)
-    return a;
-  p = jstr;
-  while ((p = _jq_memmem(p, (jstr + jlen) - p, idxstr, idxlen)) != NULL) {
-    a = jv_array_append(a, jv_number(p - jstr));
-    p += idxlen;
+  if (idxlen != 0) {
+    p = jstr;
+    while ((p = _jq_memmem(p, (jstr + jlen) - p, idxstr, idxlen)) != NULL) {
+      a = jv_array_append(a, jv_number(p - jstr));
+      p += idxlen;
+    }
   }
   jv_free(j);
   jv_free(k);