In sub_client.c, call mosquitto_destroy()
Fixes: #1513 and frees resources when someone terminates via SIGTERM or SIGINT. Signed-off-by: Basavesh Shivakumar <basavesh.shivakumar@gmail.com>
This commit is contained in:
parent
c37251c53d
commit
9bebab46ca
@ -44,7 +44,7 @@ int last_mid = 0;
|
||||
#ifndef WIN32
|
||||
void my_signal_handler(int signum)
|
||||
{
|
||||
if(signum == SIGALRM){
|
||||
if(signum == SIGALRM || signum == SIGTERM || signum == SIGINT){
|
||||
process_messages = false;
|
||||
mosquitto_disconnect_v5(mosq, MQTT_RC_DISCONNECT_WITH_WILL_MSG, cfg.disconnect_props);
|
||||
}
|
||||
@ -344,6 +344,16 @@ int main(int argc, char *argv[])
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if(sigaction(SIGTERM, &sigact, NULL) == -1){
|
||||
perror("sigaction");
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if(sigaction(SIGINT, &sigact, NULL) == -1){
|
||||
perror("sigaction");
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if(cfg.timeout){
|
||||
alarm(cfg.timeout);
|
||||
}
|
||||
@ -364,6 +374,7 @@ int main(int argc, char *argv[])
|
||||
return rc;
|
||||
|
||||
cleanup:
|
||||
mosquitto_destroy(mosq);
|
||||
mosquitto_lib_cleanup();
|
||||
client_config_cleanup(&cfg);
|
||||
return 1;
|
||||
|
Loading…
Reference in New Issue
Block a user