emqx / CocoaMQTT

MQTT 5.0 client library for iOS and macOS written in Swift
https://www.emqx.com/en
Other
1.58k stars 413 forks source link

crash with publishProperties #600

Open fighting300 opened 2 weeks ago

fighting300 commented 2 weeks ago

hello, i find a crash when send message; the ips info is blow: example 1: ` SIGSEGV: 0xffffff818ac549e0 0x0 + 6619471872


`

example 2: ` SIGSEGV: 0x0000000101287e18 $s11CommonKit_a21MqttPublishPropertiesC10propertiesSays5UInt8VGvg


`

the code of mqtt is blow:

`

how can this happen the "pubProps" is not release

it seems crash in blow code

` func properties() -> [UInt8] {

    // Properties
    return publishProperties?.properties ?? []
}

public var properties: [UInt8] {
    var properties = [UInt8]()

    //3.3.2.3.2  Payload Format Indicator
    if let payloadFormatIndicator = self.payloadFormatIndicator {
        properties += getMQTTPropertyData(type: CocoaMQTTPropertyName.payloadFormatIndicator.rawValue, value: [payloadFormatIndicator.rawValue])
    }
    //3.3.2.3.3  Message Expiry Interval
    if let messageExpiryInterval = self.messageExpiryInterval {
        properties += getMQTTPropertyData(type: CocoaMQTTPropertyName.willExpiryInterval.rawValue, value: messageExpiryInterval.byteArrayLittleEndian)
    }
    //3.3.2.3.4 Topic Alias
    if let topicAlias = self.topicAlias {
        properties += getMQTTPropertyData(type: CocoaMQTTPropertyName.topicAlias.rawValue, value: topicAlias.hlBytes)
    }
    //3.3.2.3.5 Response Topic
    if let responseTopic = self.responseTopic {
        properties += getMQTTPropertyData(type: CocoaMQTTPropertyName.responseTopic.rawValue, value: responseTopic.bytesWithLength)
    }
    //3.3.2.3.6 Correlation Data
    if let correlationData = self.correlationData {
        properties += getMQTTPropertyData(type: CocoaMQTTPropertyName.correlationData.rawValue, value: correlationData)
    }
    //3.3.2.3.7 Property Length User Property
    if let userProperty = self.userProperty {
        for (key, value) in userProperty {
            properties += getMQTTPropertyData(type: CocoaMQTTPropertyName.userProperty.rawValue, value: key.bytesWithLength + value.bytesWithLength)
        }
    }
    //3.3.2.3.8 Subscription Identifier
    if let subscriptionIdentifier = self.subscriptionIdentifier,
       let subscriptionIdentifier = beVariableByteInteger(subscriptionIdentifier) {
        properties += getMQTTPropertyData(type: CocoaMQTTPropertyName.subscriptionIdentifier.rawValue, value: subscriptionIdentifier)
    }
    //3.3.2.3.9 Content Type
    if let contentType = self.contentType {
        properties += getMQTTPropertyData(type: CocoaMQTTPropertyName.contentType.rawValue, value: contentType.bytesWithLength)
    }

    return properties
}

`

fighting300 commented 2 weeks ago

@leeway1208 @HJianBo

fighting300 commented 2 weeks ago

image ![Uploading 4eb03c20-39c4-106a-aaa1-910f0da557be.jpg…]()