diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index fe4d784cb9f..f1cd6b2d9a2 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -441,8 +441,10 @@ int32_t NSPV_rwremoterpcresp(int32_t rwflag,uint8_t *serialized,struct NSPV_remo void NSPV_remoterpc_purge(struct NSPV_remoterpcresp *ptr) { - if ( ptr != 0 ) + if ( ptr != 0 ) { + if (ptr->json) free (ptr->json); memset(ptr,0,sizeof(*ptr)); + } } // useful utility functions diff --git a/src/komodo_nSPV_defs.h b/src/komodo_nSPV_defs.h index 40d9dc02229..6d44fa732a5 100644 --- a/src/komodo_nSPV_defs.h +++ b/src/komodo_nSPV_defs.h @@ -185,8 +185,9 @@ struct NSPV_CCmtxinfo struct NSPV_remoterpcresp { + NSPV_remoterpcresp() { method[0] = '\0'; json = nullptr; } char method[64]; - char json[11000]; + char *json; }; #endif // KOMODO_NSPV_DEFSH diff --git a/src/komodo_nSPV_fullnode.h b/src/komodo_nSPV_fullnode.h index ea6156a5b2c..9a4362c1c80 100644 --- a/src/komodo_nSPV_fullnode.h +++ b/src/komodo_nSPV_fullnode.h @@ -688,6 +688,9 @@ int32_t NSPV_remoterpc(struct NSPV_remoterpcresp *ptr,char *json,int n) { rpc_result = JSONRPCReplyObj(result, NullUniValue, jreq.id); response=rpc_result.write(); + ptr->json = (char*)malloc(response.size()); + if (ptr->json == nullptr) + throw JSONRPCError(RPC_OUT_OF_MEMORY, "Cannot allocate memory for response"); memcpy(ptr->json,response.c_str(),response.size()); len+=response.size(); return (len); @@ -709,6 +712,7 @@ int32_t NSPV_remoterpc(struct NSPV_remoterpcresp *ptr,char *json,int n) rpc_result = JSONRPCReplyObj(NullUniValue,JSONRPCError(RPC_PARSE_ERROR, e.what()), jreq.id); response=rpc_result.write(); } + ptr->json = (char*)malloc(response.size()); // only not a big size error responses are here memcpy(ptr->json,response.c_str(),response.size()); len+=response.size(); return (len);