Fix JSON reference counting errors
authorJennifer Richards <jennifer@painless-security.com>
Mon, 30 Apr 2018 17:12:41 +0000 (13:12 -0400)
committerJennifer Richards <jennifer@painless-security.com>
Mon, 30 Apr 2018 17:12:41 +0000 (13:12 -0400)
mon/mon_req_decode.c
mon/mon_resp_encode.c

index 0c7e7f4..21bb64b 100644 (file)
@@ -126,7 +126,7 @@ MON_REQ *mon_req_parse(TALLOC_CTX *mem_ctx, const char *input)
  *
  * (options are optional)
  *
  *
  * (options are optional)
  *
- * Caller must free the return value with MON_REQ_free().
+ * Caller must free the return value with mon_req_free().
  *
  * @param mem_ctx talloc context for the returned struct
  * @param req_json reference to JSON request object
  *
  * @param mem_ctx talloc context for the returned struct
  * @param req_json reference to JSON request object
@@ -171,8 +171,6 @@ MON_REQ *mon_req_decode(TALLOC_CTX *mem_ctx, json_t *req_json)
 
 cleanup:
   talloc_free(tmp_ctx);
 
 cleanup:
   talloc_free(tmp_ctx);
-  if (req_json)
-    json_decref(req_json);
 
   return req;
 }
 
   return req;
 }
index 23c3dd8..7e41c65 100644 (file)
@@ -79,6 +79,7 @@ json_t *mon_resp_encode(MON_RESP *resp)
   /* If we have a payload, add it */
   if (resp->payload) {
     object_set_or_free_and_return(resp_json, jval, "payload", resp->payload);
   /* If we have a payload, add it */
   if (resp->payload) {
     object_set_or_free_and_return(resp_json, jval, "payload", resp->payload);
+    json_incref(resp->payload); /* we just created a second reference to the payload */
   }
 
   return resp_json;
   }
 
   return resp_json;