diff --git a/src/calcwit.cpp b/src/calcwit.cpp index b43305a..a8e2306 100644 --- a/src/calcwit.cpp +++ b/src/calcwit.cpp @@ -65,6 +65,13 @@ Circom_CalcWit::Circom_CalcWit (Circom_Circuit *aCircuit, uint maxTh) { Circom_CalcWit::~Circom_CalcWit() { // ... + + delete[] inputSignalAssigned; + + delete[] signalValues; + + delete[] componentMemory; + } uint Circom_CalcWit::getInputSignalHashPosition(u64 h) { diff --git a/src/circom.hpp b/src/circom.hpp index afcaf6a..1842e6c 100644 --- a/src/circom.hpp +++ b/src/circom.hpp @@ -25,20 +25,38 @@ struct __attribute__((__packed__)) HashSignalInfo { struct IODef { u32 offset; u32 len; - u32 *lengths; + u32 *lengths = nullptr; }; struct IODefPair { u32 len; - IODef* defs; + IODef* defs = nullptr; }; struct Circom_Circuit { // const char *P; - HashSignalInfo* InputHashMap; - u64* witness2SignalList; - FrElement* circuitConstants; + HashSignalInfo* InputHashMap = nullptr; + u64* witness2SignalList = nullptr; + FrElement* circuitConstants = nullptr; std::map templateInsId2IOSignalInfo; + + ~Circom_Circuit() { + + delete[] InputHashMap; + + delete[] witness2SignalList; + + delete[] circuitConstants; + + for (auto &pair : templateInsId2IOSignalInfo) { + auto *defs = pair.second.defs; + if (defs != nullptr) { + delete[] defs->lengths; + free(defs); + } + } + + } }; @@ -49,12 +67,12 @@ struct Circom_Component { std::string templateName; std::string componentName; u64 idFather; - u32* subcomponents; - bool* subcomponentsParallel; - bool *outputIsSet; //one for each output - std::mutex *mutexes; //one for each output - std::condition_variable *cvs; - std::thread *sbct; //subcomponent threads + u32* subcomponents = nullptr; + bool* subcomponentsParallel = nullptr; + bool *outputIsSet = nullptr; //one for each output + std::mutex *mutexes = nullptr; //one for each output + std::condition_variable *cvs = nullptr; + std::thread *sbct = nullptr; //subcomponent threads Circom_Component() : subcomponents(0), subcomponentsParallel(0), outputIsSet(0), mutexes(0), cvs(0), sbct(0) diff --git a/src/witnesscalc.cpp b/src/witnesscalc.cpp index 8f719ab..272c29d 100644 --- a/src/witnesscalc.cpp +++ b/src/witnesscalc.cpp @@ -78,7 +78,7 @@ Circom_Circuit* loadCircuit(const void *buffer, unsigned long buffer_size) { memcpy((void *)defs[j].lengths,(void *)(pu32+2),len*sizeof(u32)); pu32 += len + 2; } - p.defs = (IODef*)calloc(10, sizeof(IODef)); + p.defs = (IODef*)calloc(p.len, sizeof(IODef)); for (u32 j = 0; j < p.len; j++){ p.defs[j] = defs[j]; }