Fix Coverity Scan 1486959 Resource leak

pull/2505/head
Roger A. Light 4 years ago
parent cac537830e
commit 85cbe1cea6

@ -149,7 +149,6 @@ int persist__chunk_message_store_write_v6(FILE *db_fptr, struct P_base_msg *chun
uint16_t source_username_len = chunk->F.source_username_len; uint16_t source_username_len = chunk->F.source_username_len;
uint16_t topic_len = chunk->F.topic_len; uint16_t topic_len = chunk->F.topic_len;
uint32_t proplen = 0; uint32_t proplen = 0;
struct mosquitto__packet *prop_packet = NULL;
int rc; int rc;
if(chunk->properties){ if(chunk->properties){
@ -182,7 +181,7 @@ int persist__chunk_message_store_write_v6(FILE *db_fptr, struct P_base_msg *chun
} }
if(chunk->properties){ if(chunk->properties){
if(proplen > 0){ if(proplen > 0){
prop_packet = calloc(1, sizeof(struct mosquitto__packet)+proplen); struct mosquitto__packet *prop_packet = calloc(1, sizeof(struct mosquitto__packet)+proplen);
if(prop_packet == NULL){ if(prop_packet == NULL){
return MOSQ_ERR_NOMEM; return MOSQ_ERR_NOMEM;
} }
@ -190,18 +189,18 @@ int persist__chunk_message_store_write_v6(FILE *db_fptr, struct P_base_msg *chun
prop_packet->packet_length = proplen; prop_packet->packet_length = proplen;
rc = property__write_all(prop_packet, chunk->properties, true); rc = property__write_all(prop_packet, chunk->properties, true);
if(rc){ if(rc){
SAFE_FREE(prop_packet);
return rc; return rc;
} }
write_e(db_fptr, prop_packet->payload, proplen); write_e(db_fptr, prop_packet->payload, proplen);
mosquitto__FREE(prop_packet); SAFE_FREE(prop_packet);
} }
} }
return MOSQ_ERR_SUCCESS; return MOSQ_ERR_SUCCESS;
error: error:
log__printf(NULL, MOSQ_LOG_ERR, "Error: %s.", strerror(errno)); log__printf(NULL, MOSQ_LOG_ERR, "Error: %s.", strerror(errno));
mosquitto__FREE(prop_packet);
return 1; return 1;
} }

Loading…
Cancel
Save