arik-so / arik-so/ldk-parser

Add recursive deallocation prohibition flag in elided types

Open
#24 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Swift
Stars
0
Forks
2
PR merge metrics
No merged PRs in 30d

Description

When a method takes a pointer to the instance as an argument, the return type typically needs the instance's memory to stick around. For instance, take `ChannelMonitor`'s `getFundingTxo` function:

```swift
/// Gets the funding transaction outpoint of the channel this ChannelMonitor is monitoring for.
public func getFundingTxo() -> (OutPoint, [UInt8]) {
// native call variable prep

// native method call
let nativeCallResult = withUnsafePointer(to: self.cType!) { (thisArgPointer: UnsafePointer) in
ChannelMonitor_get_funding_txo(thisArgPointer)
}


// cleanup

// return value (do some wrapping)
let returnValue = Tuple_OutPointScriptZ(cType: nativeCallResult, anchor: self).getValue()

return returnValue
}
```

Here, the return type is a `Tuple_OutPointScriptZ` that takes `self` as an anchor, which guarantees that `self` will outlive the tuple, and which also dangles self. However, the `getValue()` call makes no such guarantees. If one of the tuple's components is freeable, which `OutPoint` is, it will likely still release the memory even though it shouldn't.

Worse, if the tuple were instead a multi-level vector, like `Vec_CVec_ChannelMonitorZ`, there would be multiple levels of memory deallocation potential.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with the generated ChannelMonitor.getFundingTxo example and trace Tuple_OutPointScriptZ.getValue() through its cleanup or deallocation behavior. Compare that with the nested Vec_CVec_ChannelMonitorZ case, then determine how a recursive prohibition flag should propagate and how completion would be verified for anchored return values.

Written by the indexing model from the issue text.

Assessment

Tech stack
swift
Domain
tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.