Skip to content

Commit

Permalink
In sub_client.c, call mosquitto_destroy()
Browse files Browse the repository at this point in the history
Fixes: #1513 and frees resources when someone terminates
via SIGTERM or SIGINT.

Signed-off-by: Basavesh Shivakumar <[email protected]>
  • Loading branch information
basavesh committed Nov 27, 2019
1 parent c37251c commit 9bebab4
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion client/sub_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
}
Expand All @@ -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;
Expand Down

0 comments on commit 9bebab4

Please sign in to comment.