Skip to content

Commit bcfbf23

Browse files
committed
free ziti_config memory when ZitiTunnelEvent is released
1 parent 85d2367 commit bcfbf23

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

lib/ZitiTunnelEvent.swift

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,10 +222,12 @@ import CZitiPrivate
222222

223223
/// Certificte PEM (possibly multiple certificates)
224224
public var certPEM:String = ""
225+
226+
/// pointer to result of parsing event's `config_json` field. allocated by ziti-sdk-c
227+
private var ziti_cfg_ptr:UnsafeMutablePointer<ziti_config>?
225228

226229
init(_ ziti:Ziti, _ evt:UnsafePointer<config_event>) {
227230
super.init(ziti)
228-
var ziti_cfg_ptr:UnsafeMutablePointer<ziti_config>?
229231
parse_ziti_config_ptr(&ziti_cfg_ptr, evt.pointee.config_json, strlen(evt.pointee.config_json))
230232
self.controllerUrl = toStr(ziti_cfg_ptr?.pointee.controller_url)
231233

@@ -245,6 +247,12 @@ import CZitiPrivate
245247
self.certPEM = toStr(ziti_cfg_ptr?.pointee.id.cert)
246248
}
247249

250+
deinit {
251+
if ziti_cfg_ptr != nil {
252+
free_ziti_config_ptr(ziti_cfg_ptr)
253+
}
254+
}
255+
248256
/// Debug description
249257
/// - returns: String containing debug description of this event
250258
public override var debugDescription: String {

0 commit comments

Comments
 (0)