Trying to free a msg via the MQTTClient_freeMessag...
# kotlin-native
n
Trying to free a msg via the MQTTClient_freeMessage function however it doesn't accept a CPointer<MQTTClient_message>?. The function only accepts a CValuesRef<CPointerVar<MQTTClient_message>>?. Below is the mapping for MQTTClient_message:
Copy code
@kotlinx.cinterop.internal.CStruct public final class MQTTClient_message public constructor(rawPtr: kotlinx.cinterop.NativePtr /* = kotlin.native.internal.NativePtr */) : kotlinx.cinterop.CStructVar {
    public companion object : kotlinx.cinterop.CStructVar.Type {
    }

    public final var dup: <http://kotlin.Int|kotlin.Int> /* compiled code */

    public final var msgid: <http://kotlin.Int|kotlin.Int> /* compiled code */

    public final var payload: kotlinx.cinterop.COpaquePointer? /* = kotlinx.cinterop.CPointer<out kotlinx.cinterop.CPointed>? */ /* compiled code */

    public final var payloadlen: <http://kotlin.Int|kotlin.Int> /* compiled code */

    public final val properties: paho_mqtt.MQTTProperties /* compiled code */

    public final var qos: <http://kotlin.Int|kotlin.Int> /* compiled code */

    public final var retained: <http://kotlin.Int|kotlin.Int> /* compiled code */

    public final val struct_id: kotlinx.cinterop.CArrayPointer<kotlinx.cinterop.ByteVar /* = kotlinx.cinterop.ByteVarOf<kotlin.Byte> */> /* = kotlinx.cinterop.CPointer<kotlinx.cinterop.ByteVarOf<kotlin.Byte>> */ /* compiled code */

    public final var struct_version: <http://kotlin.Int|kotlin.Int> /* compiled code */
}
Here is the callback signature:
Copy code
fun onMessageArrived(
        @Suppress("UNUSED_PARAMETER") ctx: CPointer<*>?,
        topicName: CPointer<ByteVar>?,
        topicLength: Int,
        msg: CPointer<MQTTClient_message>?
): Int
d
Looks like
MQTTClient_freeMessage
takes an array.
You can do something like,
MQTTClient_freeMessage(..., cValuesOf(msg), ....)
.
👍 1
n
Good thing that works. The program was leaking through memory in a very short space of time. Reserved memory is holding steady at 484 KB which isn't too bad considering that Kotlin Native hasn't been heavily optimised yet.