Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix memory leak caused by impl.go call libzkp #57

Closed
wants to merge 3 commits into from
Closed
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 9 additions & 18 deletions rollup/circuitcapacitychecker/impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,12 @@ func (ccc *CircuitCapacityChecker) ApplyTransaction(traces *types.BlockTrace) (*
}

tracesStr := C.CString(string(tracesByt))
defer func() {
C.free(unsafe.Pointer(tracesStr))
}()
defer C.free(unsafe.Pointer(tracesStr))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how does this change make it different?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are some subtle differences, I mainly refer to scroll's update


log.Debug("start to check circuit capacity for tx", "id", ccc.ID, "TxHash", traces.Transactions[0].TxHash)
rawResult := C.apply_tx(C.uint64_t(ccc.ID), tracesStr)
defer func() {
C.free_c_chars(rawResult)
}()
defer C.free_c_chars(rawResult)

log.Debug("check circuit capacity for tx done", "id", ccc.ID, "TxHash", traces.Transactions[0].TxHash)

result := &WrappedRowUsage{}
Expand Down Expand Up @@ -119,15 +116,11 @@ func (ccc *CircuitCapacityChecker) ApplyBlock(traces *types.BlockTrace) (*types.
}

tracesStr := C.CString(string(tracesByt))
defer func() {
C.free(unsafe.Pointer(tracesStr))
}()
defer C.free(unsafe.Pointer(tracesStr))

log.Debug("start to check circuit capacity for block", "id", ccc.ID, "blockNumber", traces.Header.Number, "blockHash", traces.Header.Hash())
rawResult := C.apply_block(C.uint64_t(ccc.ID), tracesStr)
defer func() {
C.free_c_chars(rawResult)
}()
defer C.free_c_chars(rawResult)
log.Debug("check circuit capacity for block done", "id", ccc.ID, "blockNumber", traces.Header.Number, "blockHash", traces.Header.Hash())

result := &WrappedRowUsage{}
Expand Down Expand Up @@ -157,9 +150,8 @@ func (ccc *CircuitCapacityChecker) CheckTxNum(expected int) (bool, uint64, error

log.Debug("ccc get_tx_num start", "id", ccc.ID)
rawResult := C.get_tx_num(C.uint64_t(ccc.ID))
defer func() {
C.free_c_chars(rawResult)
}()
defer C.free_c_chars(rawResult)

log.Debug("ccc get_tx_num end", "id", ccc.ID)

result := &WrappedTxNum{}
Expand All @@ -180,9 +172,8 @@ func (ccc *CircuitCapacityChecker) SetLightMode(lightMode bool) error {

log.Debug("ccc set_light_mode start", "id", ccc.ID)
rawResult := C.set_light_mode(C.uint64_t(ccc.ID), C.bool(lightMode))
defer func() {
C.free_c_chars(rawResult)
}()
defer C.free_c_chars(rawResult)

log.Debug("ccc set_light_mode end", "id", ccc.ID)

result := &WrappedCommonResult{}
Expand Down