Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[mosquitto-dev] a memory leak in packet__write function

I am using mosquitto compiled for the  ATMEL  Cortex-A5 as broker .
the borker Memory rises slowly,no stop.
I take some log in `int packet__write(struct mosquitto *mosq)`  。like that

while(packet->to_process > 0){
write_length = net__write(mosq, &(packet->payload[packet->pos]), packet->to_process);
if(write_length > 0){
G_BYTES_SENT_INC(write_length);
packet->to_process -= write_length;
packet->pos += write_length;
}else{
#ifdef WIN32
errno = WSAGetLastError();
#endif
if(errno == EAGAIN || errno == COMPAT_EWOULDBLOCK){
pthread_mutex_unlock(&mosq->current_out_packet_mutex);
log__printf(NULL, MOSQ_LOG_INFO, "(%s,mid:%d): errno == EAGAIN or COMPAT_EWOULDBLOCK",mosq->id,packet->mid );
return MOSQ_ERR_SUCCESS;// ************* no free packet
}else{
pthread_mutex_unlock(&mosq->current_out_packet_mutex);
switch(errno){
case COMPAT_ECONNRESET:
return MOSQ_ERR_CONN_LOST; // ************ no free packet
default:
return MOSQ_ERR_ERRNO; //**************** no free packet
}
}
}
}

my mqtt client is busy and cannot recv msg quickly,
when socket send buf is fill, the net__write will cause errno == EAGAIN, then return MOSQ_ERR_SUCCESS  without  free packet.



when the next message need to pub, in  packet__queue function , will check mosq->out_packet like that
pthread_mutex_lock(&mosq->out_packet_mutex);


if(mosq->out_packet){
log__printf(NULL, MOSQ_LOG_INFO, "(%s,mid:%d): package to out_packet_last->Next,command:%x: outpacket_num:%d",
mosq->id,packet->mid,mosq->out_packet->command,mosq->out_packet_count);
mosq->out_packet_last->next = packet;
}else{
log__printf(NULL, MOSQ_LOG_INFO, "(%s,mid:%d): package to out_packet:  outpacket_num:%d",
mosq->id,packet->mid,mosq->out_packet_count);
mosq->out_packet = packet;
}

mosq->out_packet_last = packet;
mosq->out_packet_count++;
pthread_mutex_unlock(&mosq->out_packet_mutex);

i found that  some time it will run: mosq->out_packet_last->next = packet;   because  last time errno == EAGAIN,package no free .

the last  I can not fun anywhere to free out_packet_last .  so the mosquitto borker Memory rises slowly.

Back to the top