fence-agents: master - fence_kdump: Fix possible problems according to Coverity

Marek GrĂ¡c marx at fedoraproject.org
Mon Mar 2 09:58:21 UTC 2015


Gitweb:        http://git.fedorahosted.org/git/?p=fence-agents.git;a=commitdiff;h=2a8f8b60da7665454d68b07a281fd36bbfec2a18
Commit:        2a8f8b60da7665454d68b07a281fd36bbfec2a18
Parent:        ed573e384055fe7f80e4bff393fcc1f091127ee3
Author:        Marek 'marx' Grac <mgrac at redhat.com>
AuthorDate:    Mon Mar 2 10:58:06 2015 +0100
Committer:     Marek 'marx' Grac <mgrac at redhat.com>
CommitterDate: Mon Mar 2 10:59:35 2015 +0100

fence_kdump: Fix possible problems according to Coverity

Previously, there was issue detected by Coverity. They do not matter too much
because we care only about return value and it will not be 0 if program crash.
But it is always better to have clean code, so fixing.
---
 fence/agents/kdump/fence_kdump.c |   21 +++++++++++----------
 1 files changed, 11 insertions(+), 10 deletions(-)

diff --git a/fence/agents/kdump/fence_kdump.c b/fence/agents/kdump/fence_kdump.c
index 29abbda..781df64 100644
--- a/fence/agents/kdump/fence_kdump.c
+++ b/fence/agents/kdump/fence_kdump.c
@@ -118,21 +118,22 @@ do_action_monitor (void)
 {
     const char cmdline_path[] = "/proc/cmdline";
     FILE *procFile;
-    size_t sz;
-    char *lines;
-    int result;
+    size_t sz = 0;
+    char *lines = NULL;
+    int result = 1;
 
     procFile = fopen(cmdline_path, "r");
-    sz = 0;
 
-    while (!feof (procFile)) {
-        getline (&lines, &sz, procFile);
+    if (procFile == NULL) {
+        log_error (0, "Unable to open file %s (%s)\n", cmdline_path, strerror (errno));
+        return 1;
     }
 
-    if (strstr(lines, "crashkernel=") == NULL) {
-        result = 1;
-    } else {
-        result = 0;
+    while (!feof (procFile)) {
+        ssize_t rv = getline (&lines, &sz, procFile);
+        if ((rv != -1) && (strstr(lines, "crashkernel=") != NULL)) {
+            result = 0;
+        }
     }
 
     free (lines);


More information about the cluster-commits mailing list