Fix based on Coverity and Sonar audits (part 8) (#22336)
tests: fix statsd-stress cleanup on send-error path Sonar c:S3584 / c:S1763: spam_thread() returned directly when sendto() failed, leaking the strdup'd per-packet strings, the packets and lengths arrays, and the UDP socket fd. The cleanup at the end of the function sat after an unconditional `for (;;)` loop, so it was unreachable. Move the cleanup into the sendto() failure path (free each packets[j] string, then free packets, free lengths, close the socket) and drop the post-loop dead code. The function still has the same single exit path (early return on send failure); GCC recognises the trailing infinite loop and does not require a fall-through return. Co-authored-by: Costa Tsaousis <costa@netdata.cloud>
Stelios Fragkakis committed
May 1, 2026 at 11:14 UTC
38ca4257ebd7213ca370c9ef45422e3dbec1d2fb
1 file changed
+5
-5
tests/profile/statsd-stress.c
+5
-5
@@ -90,16 +90,16 @@ static void *spam_thread(void *__data) {
90
for(i = 0; i < metrics ;i++) {
91
if (sendto(s, packets[i], lengths[i], 0, (void *)data->si_other, data->slen) < 0) {
92
printf("C ==> DROPPED\n");
93
+ for(size_t j = 0; j < metrics ;j++)
94
+ free(packets[j]);
95
+ free(packets);
96
+ free(lengths);
97
+ close(s);
98
return NULL;
99
}
100
data->counter++;
101
}
102
}
98
-
99
- free(packets);
100
- free(lengths);
101
- close(s);
102
- return NULL;
103
}
104
105
int main(int argc, char *argv[])