@ -66,9 +66,16 @@ int handle__unsubscribe(struct mosquitto_db *db, struct mosquitto *context)
}
}
}
}
reason_code_max = 10 ;
reason_codes = mosquitto__malloc ( reason_code_max ) ;
if ( ! reason_codes ) {
return MOSQ_ERR_NOMEM ;
}
while ( context - > in_packet . pos < context - > in_packet . remaining_length ) {
while ( context - > in_packet . pos < context - > in_packet . remaining_length ) {
sub = NULL ;
sub = NULL ;
if ( packet__read_string ( & context - > in_packet , & sub , & slen ) ) {
if ( packet__read_string ( & context - > in_packet , & sub , & slen ) ) {
mosquitto__free ( reason_codes ) ;
return 1 ;
return 1 ;
}
}
@ -77,6 +84,7 @@ int handle__unsubscribe(struct mosquitto_db *db, struct mosquitto *context)
" Empty unsubscription string from %s, disconnecting. " ,
" Empty unsubscription string from %s, disconnecting. " ,
context - > id ) ;
context - > id ) ;
mosquitto__free ( sub ) ;
mosquitto__free ( sub ) ;
mosquitto_free ( reason_codes ) ;
return 1 ;
return 1 ;
}
}
if ( mosquitto_sub_topic_check ( sub ) ) {
if ( mosquitto_sub_topic_check ( sub ) ) {
@ -84,6 +92,7 @@ int handle__unsubscribe(struct mosquitto_db *db, struct mosquitto *context)
" Invalid unsubscription string from %s, disconnecting. " ,
" Invalid unsubscription string from %s, disconnecting. " ,
context - > id ) ;
context - > id ) ;
mosquitto__free ( sub ) ;
mosquitto__free ( sub ) ;
mosquitto__free ( reason_codes ) ;
return 1 ;
return 1 ;
}
}
@ -91,12 +100,9 @@ int handle__unsubscribe(struct mosquitto_db *db, struct mosquitto *context)
rc = sub__remove ( db , context , sub , db - > subs , & reason ) ;
rc = sub__remove ( db , context , sub , db - > subs , & reason ) ;
log__printf ( NULL , MOSQ_LOG_UNSUBSCRIBE , " %s %s " , context - > id , sub ) ;
log__printf ( NULL , MOSQ_LOG_UNSUBSCRIBE , " %s %s " , context - > id , sub ) ;
mosquitto__free ( sub ) ;
mosquitto__free ( sub ) ;
if ( rc ) return rc ;
if ( rc ) {
mosquitto_fee ( reason_codes ) ;
reason_code_max = 10 ;
return rc ;
reason_codes = mosquitto__malloc ( reason_code_max ) ;
if ( ! reason_codes ) {
return MOSQ_ERR_NOMEM ;
}
}
reason_codes [ reason_code_count ] = reason ;
reason_codes [ reason_code_count ] = reason ;