hello, I am using dylibs and using c library.
I am opening the dylibs and using some of the function properly. However, some of the other functions are giving me errors relating to freeing pointers. here is one of the function below.
first I open the dl and save it as variable in a class
let dylib = dlopen("x.dylib", RTLD_NOW)
then i create type alias for the function
typealias LoadConfiguration = @convention(c) (ath_conf_t)> -> Void
then here is the function to call the function of c
func LoadConfigLib(athConfT : inout ath_conf_t) -> Void?{
guard dylib != nil else {
errorDylib()
return nil
}
guard let sym = dlsym(dylib, "LoadConfiguration") else {
errorDylib()
return nil
}
let f = unsafeBitCast(sym, to: LoadConfiguration.self)
let result: Void = f(athConfT)
print(result)
return result
}
here is the error.
malloc: *** error for object 0x102665cc0: pointer being freed was not allocated
malloc: *** set a breakpoint in malloc_error_break to debug things
I am not certain how to fix this problem or how to approach this. any sorts of guidance would be appreciated
here is the ath_conf_t
public class ath_conf_t : NSObject {
public var version: CInt
public var channels: NSArray
init(version: CInt = 0, channels: NSArray = Array(repeating: ath_channel_t.init(arg1: false, arg2: 0, adaptiveHigh: 0, arg3: 0), count: constant) as NSArray) {
self.version = version
self.channels = channels
}
}
The code you posted looks reasonable [1]. If you set a breakpoint on malloc_error_break
, what does the backtrace look like?
Share and Enjoy
—
Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"
[1] The only thing that doesn’t make sense to me is why the athConfT
parameter is inout
.