Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

In sub_client.c, call mosquitto_destroy() in cleanup label. #1514

Merged
merged 1 commit into from Nov 28, 2019
Merged

In sub_client.c, call mosquitto_destroy() in cleanup label. #1514

merged 1 commit into from Nov 28, 2019

Conversation

basavesh
Copy link
Contributor

Fixes #1513
Signed-off-by: Basavesh Shivakumar [email protected]

  • [N/A] If you are contributing a new feature, is your work based off the develop branch?
  • [Y] If you are contributing a bugfix, is your work based off the fixes branch?
  • [Y] Have you added an explanation of what your changes do and why you'd like us to include them?
  • [Y] Have you successfully run make test with your changes locally?
  • [Y] Have you signed the Eclipse Contributor Agreement, using the same email address as you used in your commits?
  • [Y] Do each of your commits have a "Signed-off-by" line, with the correct email address? Use "git commit -s" to generate this line for you.

@basavesh
Copy link
Contributor Author

@ralight,
I'm not 100% sure if it is OK to call mosquitto_destroy even when there is an error from SIGALRM sigaction. If that is not OK, I can call mosquitto_destroy during the error return status check of client_connect().

alternative fix:
rc = client_connect(mosq, &cfg); if(rc){ mosquitto_destroy(mosq); goto cleanup; }

After fix:
Invoking mosquitto_sub when the server is not up / available.

valgrind --tool=memcheck --leak-check=yes --show-reachable=yes --num-callers=20 --track-fds=yes ./mosquitto_sub -v -t test
==28378== Memcheck, a memory error detector
==28378== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==28378== Using Valgrind-3.13.0 and LibVEX; rerun with -h for copyright info
==28378== Command: ./mosquitto_sub -v -t test
==28378==
Error: Connection refused
==28378==
==28378== FILE DESCRIPTORS: 3 open at exit.
==28378== Open file descriptor 2: /dev/pts/5
==28378==
==28378==
==28378== Open file descriptor 1: /dev/pts/5
==28378==
==28378==
==28378== Open file descriptor 0: /dev/pts/5
==28378==
==28378==
==28378==
==28378== HEAP SUMMARY:
==28378== in use at exit: 0 bytes in 0 blocks
==28378== total heap usage: 3,780 allocs, 3,780 frees, 176,188 bytes allocated
==28378==
==28378== All heap blocks were freed -- no leaks are possible
==28378==
==28378== For counts of detected and suppressed errors, rerun with: -v
==28378== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)

@basavesh
Copy link
Contributor Author

I amended the commit to handling SIGTERM and SIGINT signals to gracefully shutdown.
Otherwise, Valgrind will complain when we terminate the mosquitto_sub via CTRL+C

Fixes: #1513 and frees resources when someone terminates
via SIGTERM or SIGINT.

Signed-off-by: Basavesh Shivakumar <[email protected]>
@ralight ralight merged commit 757e88e into eclipse:fixes Nov 28, 2019
@ralight
Copy link
Contributor

ralight commented Nov 28, 2019

I don't think this was causing many problems as it was, but it's nice to have things cleaned up. Thanks very much.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 11, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants