Merge branch 'bugfix-MemLeak_in_handle_unsubscribe' of git://github.com/panava/mosquitto into panava-bugfix-MemLeak_in_handle_unsubscribe

This commit is contained in:
Roger A. Light 2020-01-30 12:48:32 +00:00
commit 11ece604c4
2 changed files with 8 additions and 2 deletions

View File

@ -185,6 +185,7 @@ int socks5__send(struct mosquitto *mosq)
}else{
slen = strlen(mosq->host);
if(slen > UCHAR_MAX){
mosquitto__free(packet);
return MOSQ_ERR_NOMEM;
}
packet->packet_length = 7 + slen;

View File

@ -75,6 +75,7 @@ int handle__unsubscribe(struct mosquitto_db *db, struct mosquitto *context)
while(context->in_packet.pos < context->in_packet.remaining_length){
sub = NULL;
if(packet__read_string(&context->in_packet, &sub, &slen)){
mosquitto__free(reason_codes);
return 1;
}
@ -83,6 +84,7 @@ int handle__unsubscribe(struct mosquitto_db *db, struct mosquitto *context)
"Empty unsubscription string from %s, disconnecting.",
context->id);
mosquitto__free(sub);
mosquitto__free(reason_codes);
return 1;
}
if(mosquitto_sub_topic_check(sub)){
@ -90,6 +92,7 @@ int handle__unsubscribe(struct mosquitto_db *db, struct mosquitto *context)
"Invalid unsubscription string from %s, disconnecting.",
context->id);
mosquitto__free(sub);
mosquitto__free(reason_codes);
return 1;
}
@ -97,7 +100,10 @@ int handle__unsubscribe(struct mosquitto_db *db, struct mosquitto *context)
rc = sub__remove(db, context, sub, db->subs, &reason);
log__printf(NULL, MOSQ_LOG_UNSUBSCRIBE, "%s %s", context->id, sub);
mosquitto__free(sub);
if(rc) return rc;
if(rc){
mosquitto__free(reason_codes);
return rc;
}
reason_codes[reason_code_count] = reason;
reason_code_count++;
@ -122,4 +128,3 @@ int handle__unsubscribe(struct mosquitto_db *db, struct mosquitto *context)
mosquitto__free(reason_codes);
return rc;
}