dont crash when netdata cannot execute its external plugins (#13978)
Costa Tsaousis committed
Nov 11, 2022 at 09:46 UTC
6dec9601f9def04211cb59f8df63567eacfa5480
1 file changed
+12
-6
libnetdata/popen/popen.c
+12
-6
@@ -168,7 +168,8 @@ static int popene_internal(volatile pid_t *pidptr, char **env, uint8_t flags, FI
168
169
if(posix_spawn_file_actions_init(&fa)) {
170
error("POPEN: posix_spawn_file_actions_init() failed.");
171
- return -1;
171
+ ret = -1;
172
+ goto set_return_values_and_return;
173
}
174
175
if(fpp_child_stdin) {
@@ -292,9 +293,8 @@ cleanup_and_return:
293
fclose(fp_child_stdin);
294
else if (pipefd_stdin[PIPE_WRITE] != -1)
295
close(pipefd_stdin[PIPE_WRITE]);
295
- }
296
- else {
297
- *fpp_child_stdin = fp_child_stdin;
296
+
297
+ fp_child_stdin = NULL;
298
}
299
300
// the child end - close it
@@ -307,10 +307,16 @@ cleanup_and_return:
307
fclose(fp_child_stdout);
308
else if (pipefd_stdout[PIPE_READ] != -1)
309
close(pipefd_stdout[PIPE_READ]);
310
+
311
+ fp_child_stdout = NULL;
312
}
311
- else {
313
+
314
+set_return_values_and_return:
315
+ if(fpp_child_stdin)
316
+ *fpp_child_stdin = fp_child_stdin;
317
+
318
+ if(fpp_child_stdout)
319
*fpp_child_stdout = fp_child_stdout;
313
- }
320
321
return ret;
322
}