summaryrefslogtreecommitdiffstats
path: root/libnetdata
diff options
context:
space:
mode:
authorCosta Tsaousis <costa@netdata.cloud>2022-11-11 09:46:35 +0200
committerGitHub <noreply@github.com>2022-11-11 09:46:35 +0200
commit6dec9601f9def04211cb59f8df63567eacfa5480 (patch)
treedda7e6a327ca2616c74f8e318baa7a45bd510283 /libnetdata
parent0036c363f469d1ce946564b8bafea8c7d1136678 (diff)
dont crash when netdata cannot execute its external plugins (#13978)
Diffstat (limited to 'libnetdata')
-rw-r--r--libnetdata/popen/popen.c18
1 files changed, 12 insertions, 6 deletions
diff --git a/libnetdata/popen/popen.c b/libnetdata/popen/popen.c
index b67d6b096b..57f957f636 100644
--- a/libnetdata/popen/popen.c
+++ b/libnetdata/popen/popen.c
@@ -168,7 +168,8 @@ static int popene_internal(volatile pid_t *pidptr, char **env, uint8_t flags, FI
if(posix_spawn_file_actions_init(&fa)) {
error("POPEN: posix_spawn_file_actions_init() failed.");
- return -1;
+ ret = -1;
+ goto set_return_values_and_return;
}
if(fpp_child_stdin) {
@@ -292,9 +293,8 @@ cleanup_and_return:
fclose(fp_child_stdin);
else if (pipefd_stdin[PIPE_WRITE] != -1)
close(pipefd_stdin[PIPE_WRITE]);
- }
- else {
- *fpp_child_stdin = fp_child_stdin;
+
+ fp_child_stdin = NULL;
}
// the child end - close it
@@ -307,10 +307,16 @@ cleanup_and_return:
fclose(fp_child_stdout);
else if (pipefd_stdout[PIPE_READ] != -1)
close(pipefd_stdout[PIPE_READ]);
+
+ fp_child_stdout = NULL;
}
- else {
+
+set_return_values_and_return:
+ if(fpp_child_stdin)
+ *fpp_child_stdin = fp_child_stdin;
+
+ if(fpp_child_stdout)
*fpp_child_stdout = fp_child_stdout;
- }
return ret;
}