@cryptotaxi247 / netdata-1 / commits / 674e9f4f2

properly cleanup statsd on exit

Costa Tsaousis (ktsaou) committed Jun 7, 2017 at 22:00 UTC 674e9f4f28b60d168300f7ebe6f13669d99f410a
1 file changed +18 -11
src/statsd.c
+18 -11
@@ -861,6 +861,22 @@ static int statsd_snd_callback(int fd, int socktype, void *data, short int *even
861 // --------------------------------------------------------------------------------------------------------------------
862 // statsd child thread to collect metrics from network
863
864 +void statsd_collector_thread_cleanup(void *data) {
865 + struct statsd_udp *d = data;
866 +
867 +#ifdef HAVE_RECVMMSG
868 + size_t i;
869 + for (i = 0; i < d->size; i++)
870 + freez(d->iovecs[i].iov_base);
871 +
872 + freez(d->iovecs);
873 + freez(d->msgs);
874 +#endif
875 +
876 + freez(d);
877 + listen_sockets_close(&statsd.sockets);
878 +}
879 +
880 void *statsd_collector_thread(void *ptr) {
881 int id = *((int *)ptr);
882
@@ -873,6 +889,7 @@ void *statsd_collector_thread(void *ptr) {
889 error("Cannot set pthread cancel state to ENABLE.");
890
891 struct statsd_udp *d = callocz(sizeof(struct statsd_udp), 1);
892 + pthread_cleanup_push(statsd_collector_thread_cleanup, d);
893
894 #ifdef HAVE_RECVMMSG
895 d->type = STATSD_SOCKET_DATA_TYPE_UDP;
@@ -897,19 +914,9 @@ void *statsd_collector_thread(void *ptr) {
914 , (void *)d
915 );
916
900 -#ifdef HAVE_RECVMMSG
901 - for (i = 0; i < d->size; i++)
902 - freez(d->iovecs[i].iov_base);
903 -
904 - freez(d->iovecs);
905 - freez(d->msgs);
906 -#endif
907 -
908 - freez(d);
917 + pthread_cleanup_pop(1);
918
919 debug(D_WEB_CLIENT, "STATSD: exit!");
911 - listen_sockets_close(&statsd.sockets);
912 -
920 pthread_exit(NULL);
921 return NULL;
922 }