Skip to content

Commit

Permalink
Merge pull request #1514 from basavesh/fixes
Browse files Browse the repository at this point in the history
In sub_client.c, call mosquitto_destroy() in cleanup label.
  • Loading branch information
ralight authored Nov 28, 2019
2 parents 6dec2b4 + 9bebab4 commit 757e88e
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 757e88e

Please sign in to comment.