diff options
author | thiagoftsm <thiagoftsm@gmail.com> | 2019-09-20 11:45:11 +0000 |
---|---|---|
committer | Chris Akritidis <43294513+cakrit@users.noreply.github.com> | 2019-09-20 13:45:11 +0200 |
commit | f555472a8ceb189407b103570be9a28031819d4b (patch) | |
tree | f6033bcc7c9f2c29b0320f360d9e8d95ed228f01 /libnetdata | |
parent | 46c4b8809cad6a0dc65d91e54429e8a7a581c5a2 (diff) |
Fix some errors reported by Coverity (#6797)
* coverity_20190905: Fix reported bugs
This commit has fixes for some bugs reported by Coverity in the present day
* coverity_20190905: Fix missing report
FIx a missing report of error
* coverity_20190905: Pipe close
The previous fix had an error that wolud allow a socket continue opened, this commit fixes this
* coverity_20190905: Error pattern
The call of perror would generate a different error report, instead I am using strerror() to keep pattern
* coverity_20190905: Error function
Rewrite the call to error function
* coverity_20190905: Fix missing tests
The previous fix did not have correct tests after to clean the variables
* coverity_20190905: Fix readable
I changed for an else instead a new if, it is more clean this way
* coverity_20190905: remove unecessary test
This commit is removing an unecessary test for a variable that will never be NULL.
* coverity_20190905: Add neccessary NULLL
After to clean the variable, I am setting NULL to variable to avoid clean again
* coverity_20190905: Remove false error
The condition added to fix Coverity was generating false positives, so we are changing to debug
* coverity_20190905: Remove false error
The condition added to fix Coverity was generating false positives, so we are changing to debug
* coverity_20190905: Bring else to avoid error
Bring an else to solve the problem to read a FD not opened
* coverity_20190905: Return
After to analyse the last changes, I decided to return, because they were not necessary
* coverity_20190905: Remove NULL
Remove unecessary set of variable to NULL
Diffstat (limited to 'libnetdata')
-rw-r--r-- | libnetdata/popen/popen.c | 10 | ||||
-rw-r--r-- | libnetdata/url/url.c | 17 |
2 files changed, 7 insertions, 20 deletions
diff --git a/libnetdata/popen/popen.c b/libnetdata/popen/popen.c index 177aebfc04..906b105357 100644 --- a/libnetdata/popen/popen.c +++ b/libnetdata/popen/popen.c @@ -68,7 +68,7 @@ static inline FILE *custom_popene(const char *command, volatile pid_t *pidptr, c int i; for(i = (int) (sysconf(_SC_OPEN_MAX) - 1); i >= 0; i--) if(i != STDIN_FILENO && i != STDERR_FILENO) - fcntl(i, F_SETFD, FD_CLOEXEC); + (void)fcntl(i, F_SETFD, FD_CLOEXEC); if (!posix_spawn_file_actions_init(&fa)) { // move the pipe to stdout in the child @@ -97,7 +97,7 @@ static inline FILE *custom_popene(const char *command, volatile pid_t *pidptr, c debug(D_CHILDS, "Spawned command: '%s' on pid %d from parent pid %d.", command, pid, getpid()); } else { error("Failed to spawn command: '%s' from parent pid %d.", command, getpid()); - close(pipefd[PIPE_READ]); + fclose(fp); fp = NULL; } close(pipefd[PIPE_WRITE]); @@ -116,7 +116,11 @@ error_after_posix_spawn_file_actions_init: if (posix_spawn_file_actions_destroy(&fa)) error("posix_spawn_file_actions_destroy"); error_after_pipe: - close(pipefd[PIPE_READ]); + if (fp) + fclose(fp); + else + close(pipefd[PIPE_READ]); + close(pipefd[PIPE_WRITE]); return NULL; } diff --git a/libnetdata/url/url.c b/libnetdata/url/url.c index 7df9faaf02..d1d5081397 100644 --- a/libnetdata/url/url.c +++ b/libnetdata/url/url.c @@ -44,23 +44,6 @@ char *url_encode(char *str) { } /** - * URL Decode - * - * Returns a url-decoded version of str - * IMPORTANT: be sure to free() the returned string after use - * - * @param str the string that will be decode - * - * @return a pointer for the url decoded. - */ -char *url_decode(char *str) { - size_t size = strlen(str) + 1; - - char *buf = mallocz(size); - return url_decode_r(buf, str, size); -} - -/** * Percentage escape decode * * Decode %XX character or return 0 if cannot |