From: Ruben Kerkhof Date: Tue, 9 Oct 2018 08:36:48 +0000 (+0200) Subject: ntpd: plug potential leak on error X-Git-Url: https://git.octo.it/?a=commitdiff_plain;h=f5c3d7b736b81b0ce936b4aefbb7edbf6cf8bf3a;p=collectd.git ntpd: plug potential leak on error Found by scan-build: src/ntpd.c:833:5: warning: Potential memory leak ERROR("ntpd plugin: ntpd_do_query (REQ_GET_KERNEL) failed with status %i", ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ./src/daemon/plugin.h:391:20: note: expanded from macro 'ERROR' ^~~~~~~~~~ 1 warning generated. --- diff --git a/src/ntpd.c b/src/ntpd.c index 0faf2a2a..9b4ba60c 100644 --- a/src/ntpd.c +++ b/src/ntpd.c @@ -832,11 +832,13 @@ static int ntpd_read(void) { if (status != 0) { ERROR("ntpd plugin: ntpd_do_query (REQ_GET_KERNEL) failed with status %i", status); + free(ik); return status; } else if ((ik == NULL) || (ik_num == 0) || (ik_size == 0)) { ERROR("ntpd plugin: ntpd_do_query returned unexpected data. " "(ik = %p; ik_num = %i; ik_size = %i)", (void *)ik, ik_num, ik_size); + free(ik); return -1; }