|
|
01add4 |
From 481ac50e3e9ad53e4f07dce04facfaef5a2cdcfd Mon Sep 17 00:00:00 2001
|
|
|
01add4 |
From: Martin Milata <mmilata@redhat.com>
|
|
|
01add4 |
Date: Thu, 5 Mar 2015 14:08:15 +0100
|
|
|
01add4 |
Subject: [PATCH] Fix defects found by coverity
|
|
|
01add4 |
|
|
|
01add4 |
Resolves: #1336390
|
|
|
01add4 |
|
|
|
01add4 |
Signed-off-by: Martin Milata <mmilata@redhat.com>
|
|
|
01add4 |
|
|
|
01add4 |
Conflicts:
|
|
|
01add4 |
lib/abrt.c
|
|
|
01add4 |
---
|
|
|
01add4 |
lib/core_stacktrace.c | 8 ++++++++
|
|
|
01add4 |
lib/core_unwind.c | 6 ++++--
|
|
|
01add4 |
lib/java_frame.c | 3 +++
|
|
|
01add4 |
lib/koops_stacktrace.c | 3 +++
|
|
|
01add4 |
lib/python_frame.c | 26 ++++++++++++++------------
|
|
|
01add4 |
lib/rpm.c | 4 +++-
|
|
|
01add4 |
lib/utils.c | 1 +
|
|
|
01add4 |
python/py_gdb_stacktrace.c | 8 ++++++++
|
|
|
01add4 |
satyr.c | 3 +++
|
|
|
01add4 |
9 files changed, 47 insertions(+), 15 deletions(-)
|
|
|
01add4 |
|
|
|
01add4 |
diff --git a/lib/core_stacktrace.c b/lib/core_stacktrace.c
|
|
|
01add4 |
index f7fd369..aeb97e4 100644
|
|
|
01add4 |
--- a/lib/core_stacktrace.c
|
|
|
01add4 |
+++ b/lib/core_stacktrace.c
|
|
|
01add4 |
@@ -192,7 +192,10 @@ sr_core_stacktrace_from_json(struct sr_json_value *root,
|
|
|
01add4 |
if (crash_thread)
|
|
|
01add4 |
{
|
|
|
01add4 |
if (!JSON_CHECK_TYPE(crash_thread, SR_JSON_BOOLEAN, "crash_thread"))
|
|
|
01add4 |
+ {
|
|
|
01add4 |
+ sr_core_thread_free(thread);
|
|
|
01add4 |
goto fail;
|
|
|
01add4 |
+ }
|
|
|
01add4 |
|
|
|
01add4 |
if (crash_thread->u.boolean)
|
|
|
01add4 |
result->crash_thread = thread;
|
|
|
01add4 |
@@ -296,6 +299,7 @@ sr_core_stacktrace_create(const char *gdb_stacktrace_text,
|
|
|
01add4 |
{
|
|
|
01add4 |
warn("Unable to parse unstrip output.");
|
|
|
01add4 |
|
|
|
01add4 |
+ sr_gdb_stacktrace_free(gdb_stacktrace);
|
|
|
01add4 |
return NULL;
|
|
|
01add4 |
}
|
|
|
01add4 |
|
|
|
01add4 |
@@ -332,6 +336,8 @@ sr_core_stacktrace_create(const char *gdb_stacktrace_text,
|
|
|
01add4 |
core_frame->function_name =
|
|
|
01add4 |
sr_strdup(gdb_frame->function_name);
|
|
|
01add4 |
}
|
|
|
01add4 |
+
|
|
|
01add4 |
+ core_thread->frames = sr_core_frame_append(core_thread->frames, core_frame);
|
|
|
01add4 |
}
|
|
|
01add4 |
|
|
|
01add4 |
core_stacktrace->threads =
|
|
|
01add4 |
@@ -341,6 +347,8 @@ sr_core_stacktrace_create(const char *gdb_stacktrace_text,
|
|
|
01add4 |
gdb_thread = gdb_thread->next;
|
|
|
01add4 |
}
|
|
|
01add4 |
|
|
|
01add4 |
+ sr_unstrip_free(unstrip);
|
|
|
01add4 |
+ sr_gdb_stacktrace_free(gdb_stacktrace);
|
|
|
01add4 |
return core_stacktrace;
|
|
|
01add4 |
}
|
|
|
01add4 |
|
|
|
01add4 |
diff --git a/lib/core_unwind.c b/lib/core_unwind.c
|
|
|
01add4 |
index c30f9db..b8c0235 100644
|
|
|
01add4 |
--- a/lib/core_unwind.c
|
|
|
01add4 |
+++ b/lib/core_unwind.c
|
|
|
01add4 |
@@ -127,6 +127,7 @@ find_elf_core (Dwfl_Module *mod, void **userdata, const char *modname,
|
|
|
01add4 |
{
|
|
|
01add4 |
warn("Unable to open executable '%s': %s", executable_file,
|
|
|
01add4 |
elf_errmsg(-1));
|
|
|
01add4 |
+ close(fd);
|
|
|
01add4 |
return -1;
|
|
|
01add4 |
}
|
|
|
01add4 |
|
|
|
01add4 |
@@ -399,9 +400,10 @@ struct sr_core_stacktrace *
|
|
|
01add4 |
sr_core_stacktrace_from_gdb(const char *gdb_output, const char *core_file,
|
|
|
01add4 |
const char *exe_file, char **error_msg)
|
|
|
01add4 |
{
|
|
|
01add4 |
+ /* I'm not going to rewrite it now since the function is not being used. */
|
|
|
01add4 |
+ assert(error_msg);
|
|
|
01add4 |
/* Initialize error_msg to 'no error'. */
|
|
|
01add4 |
- if (error_msg)
|
|
|
01add4 |
- *error_msg = NULL;
|
|
|
01add4 |
+ *error_msg = NULL;
|
|
|
01add4 |
|
|
|
01add4 |
struct core_handle *ch = open_coredump(core_file, exe_file, error_msg);
|
|
|
01add4 |
if (*error_msg)
|
|
|
01add4 |
diff --git a/lib/java_frame.c b/lib/java_frame.c
|
|
|
01add4 |
index ee97572..d03f86a 100644
|
|
|
01add4 |
--- a/lib/java_frame.c
|
|
|
01add4 |
+++ b/lib/java_frame.c
|
|
|
01add4 |
@@ -359,7 +359,10 @@ sr_java_frame_parse_exception(const char **input,
|
|
|
01add4 |
if (exception->next == NULL)
|
|
|
01add4 |
exception->next = parsed;
|
|
|
01add4 |
else
|
|
|
01add4 |
+ {
|
|
|
01add4 |
+ assert(frame);
|
|
|
01add4 |
frame->next = parsed;
|
|
|
01add4 |
+ }
|
|
|
01add4 |
|
|
|
01add4 |
frame = parsed;
|
|
|
01add4 |
}
|
|
|
01add4 |
diff --git a/lib/koops_stacktrace.c b/lib/koops_stacktrace.c
|
|
|
01add4 |
index 611c7d1..01baa79 100644
|
|
|
01add4 |
--- a/lib/koops_stacktrace.c
|
|
|
01add4 |
+++ b/lib/koops_stacktrace.c
|
|
|
01add4 |
@@ -506,7 +506,10 @@ taint_flags_to_json(struct sr_koops_stacktrace *stacktrace)
|
|
|
01add4 |
}
|
|
|
01add4 |
|
|
|
01add4 |
if (strbuf->len == 0)
|
|
|
01add4 |
+ {
|
|
|
01add4 |
+ sr_strbuf_free(strbuf);
|
|
|
01add4 |
return sr_strdup("[]");
|
|
|
01add4 |
+ }
|
|
|
01add4 |
|
|
|
01add4 |
sr_strbuf_append_char(strbuf, ']');
|
|
|
01add4 |
char *result = sr_strbuf_free_nobuf(strbuf);
|
|
|
01add4 |
diff --git a/lib/python_frame.c b/lib/python_frame.c
|
|
|
01add4 |
index b0540fe..4b4be8a 100644
|
|
|
01add4 |
--- a/lib/python_frame.c
|
|
|
01add4 |
+++ b/lib/python_frame.c
|
|
|
01add4 |
@@ -220,11 +220,10 @@ sr_python_frame_parse(const char **input,
|
|
|
01add4 |
/* Parse file name */
|
|
|
01add4 |
if (!sr_parse_char_cspan(&local_input, "\"", &frame->file_name))
|
|
|
01add4 |
{
|
|
|
01add4 |
- sr_python_frame_free(frame);
|
|
|
01add4 |
location->message = sr_asprintf("Unable to find the '\"' character "
|
|
|
01add4 |
"identifying the beginning of file name.");
|
|
|
01add4 |
|
|
|
01add4 |
- return NULL;
|
|
|
01add4 |
+ goto fail;
|
|
|
01add4 |
}
|
|
|
01add4 |
|
|
|
01add4 |
if (strlen(frame->file_name) > 0 &&
|
|
|
01add4 |
@@ -243,7 +242,7 @@ sr_python_frame_parse(const char **input,
|
|
|
01add4 |
if (0 == sr_skip_string(&local_input, "\", line "))
|
|
|
01add4 |
{
|
|
|
01add4 |
location->message = sr_asprintf("Line separator not found.");
|
|
|
01add4 |
- return NULL;
|
|
|
01add4 |
+ goto fail;
|
|
|
01add4 |
}
|
|
|
01add4 |
|
|
|
01add4 |
location->column += strlen("\", line ");
|
|
|
01add4 |
@@ -253,7 +252,7 @@ sr_python_frame_parse(const char **input,
|
|
|
01add4 |
if (0 == length)
|
|
|
01add4 |
{
|
|
|
01add4 |
location->message = sr_asprintf("Line number not found.");
|
|
|
01add4 |
- return NULL;
|
|
|
01add4 |
+ goto fail;
|
|
|
01add4 |
}
|
|
|
01add4 |
|
|
|
01add4 |
location->column += length;
|
|
|
01add4 |
@@ -263,7 +262,7 @@ sr_python_frame_parse(const char **input,
|
|
|
01add4 |
if (local_input[0] != '\n')
|
|
|
01add4 |
{
|
|
|
01add4 |
location->message = sr_asprintf("Function name separator not found.");
|
|
|
01add4 |
- return NULL;
|
|
|
01add4 |
+ goto fail;
|
|
|
01add4 |
}
|
|
|
01add4 |
|
|
|
01add4 |
/* The last frame of SyntaxError stack trace does not have
|
|
|
01add4 |
@@ -280,11 +279,10 @@ sr_python_frame_parse(const char **input,
|
|
|
01add4 |
/* Parse function name */
|
|
|
01add4 |
if (!sr_parse_char_cspan(&local_input, "\n", &frame->function_name))
|
|
|
01add4 |
{
|
|
|
01add4 |
- sr_python_frame_free(frame);
|
|
|
01add4 |
location->message = sr_asprintf("Unable to find the newline character "
|
|
|
01add4 |
"identifying the end of function name.");
|
|
|
01add4 |
|
|
|
01add4 |
- return NULL;
|
|
|
01add4 |
+ goto fail;
|
|
|
01add4 |
}
|
|
|
01add4 |
|
|
|
01add4 |
location->column += strlen(frame->function_name);
|
|
|
01add4 |
@@ -301,19 +299,23 @@ sr_python_frame_parse(const char **input,
|
|
|
01add4 |
}
|
|
|
01add4 |
}
|
|
|
01add4 |
|
|
|
01add4 |
- sr_skip_char(&local_input, '\n');
|
|
|
01add4 |
- sr_location_add(location, 1, 0);
|
|
|
01add4 |
+ if (sr_skip_char(&local_input, '\n'))
|
|
|
01add4 |
+ sr_location_add(location, 1, 0);
|
|
|
01add4 |
|
|
|
01add4 |
/* Parse source code line (optional). */
|
|
|
01add4 |
if (4 == sr_skip_string(&local_input, " "))
|
|
|
01add4 |
{
|
|
|
01add4 |
- sr_parse_char_cspan(&local_input, "\n", &frame->line_contents);
|
|
|
01add4 |
- sr_skip_char(&local_input, '\n');
|
|
|
01add4 |
- sr_location_add(location, 1, 0);
|
|
|
01add4 |
+ if (sr_parse_char_cspan(&local_input, "\n", &frame->line_contents)
|
|
|
01add4 |
+ && sr_skip_char(&local_input, '\n'))
|
|
|
01add4 |
+ sr_location_add(location, 1, 0);
|
|
|
01add4 |
}
|
|
|
01add4 |
|
|
|
01add4 |
*input = local_input;
|
|
|
01add4 |
return frame;
|
|
|
01add4 |
+
|
|
|
01add4 |
+fail:
|
|
|
01add4 |
+ sr_python_frame_free(frame);
|
|
|
01add4 |
+ return NULL;
|
|
|
01add4 |
}
|
|
|
01add4 |
|
|
|
01add4 |
char *
|
|
|
01add4 |
diff --git a/lib/rpm.c b/lib/rpm.c
|
|
|
01add4 |
index f8f1fa6..920e145 100644
|
|
|
01add4 |
--- a/lib/rpm.c
|
|
|
01add4 |
+++ b/lib/rpm.c
|
|
|
01add4 |
@@ -199,7 +199,9 @@ sr_rpm_package_sort(struct sr_rpm_package *packages)
|
|
|
01add4 |
array[loop]->next = NULL;
|
|
|
01add4 |
}
|
|
|
01add4 |
|
|
|
01add4 |
- return array[0];
|
|
|
01add4 |
+ struct sr_rpm_package *result = array[0];
|
|
|
01add4 |
+ free(array);
|
|
|
01add4 |
+ return result;
|
|
|
01add4 |
}
|
|
|
01add4 |
|
|
|
01add4 |
static struct sr_rpm_package *
|
|
|
01add4 |
diff --git a/lib/utils.c b/lib/utils.c
|
|
|
01add4 |
index fa3c0a0..bdafaa7 100644
|
|
|
01add4 |
--- a/lib/utils.c
|
|
|
01add4 |
+++ b/lib/utils.c
|
|
|
01add4 |
@@ -354,6 +354,7 @@ sr_string_to_file(const char *filename,
|
|
|
01add4 |
filename,
|
|
|
01add4 |
error);
|
|
|
01add4 |
|
|
|
01add4 |
+ close(fd);
|
|
|
01add4 |
return false;
|
|
|
01add4 |
}
|
|
|
01add4 |
|
|
|
01add4 |
diff --git a/python/py_gdb_stacktrace.c b/python/py_gdb_stacktrace.c
|
|
|
01add4 |
index c799e06..5ed3533 100644
|
|
|
01add4 |
--- a/python/py_gdb_stacktrace.c
|
|
|
01add4 |
+++ b/python/py_gdb_stacktrace.c
|
|
|
01add4 |
@@ -7,6 +7,7 @@
|
|
|
01add4 |
#include "strbuf.h"
|
|
|
01add4 |
#include "gdb/stacktrace.h"
|
|
|
01add4 |
#include "gdb/thread.h"
|
|
|
01add4 |
+#include "gdb/frame.h"
|
|
|
01add4 |
#include "gdb/sharedlib.h"
|
|
|
01add4 |
#include "location.h"
|
|
|
01add4 |
#include "normalize.h"
|
|
|
01add4 |
@@ -408,13 +409,20 @@ sr_py_gdb_stacktrace_find_crash_frame(PyObject *self, PyObject *args)
|
|
|
01add4 |
PyObject_New(struct sr_py_gdb_frame, &sr_py_gdb_frame_type);
|
|
|
01add4 |
|
|
|
01add4 |
if (!result)
|
|
|
01add4 |
+ {
|
|
|
01add4 |
+ sr_gdb_frame_free(frame);
|
|
|
01add4 |
return PyErr_NoMemory();
|
|
|
01add4 |
+ }
|
|
|
01add4 |
|
|
|
01add4 |
result->frame = frame;
|
|
|
01add4 |
this->crashframe = result;
|
|
|
01add4 |
|
|
|
01add4 |
if (stacktrace_rebuild_thread_python_list(this) < 0)
|
|
|
01add4 |
+ {
|
|
|
01add4 |
+ sr_gdb_frame_free(frame);
|
|
|
01add4 |
+ Py_DECREF(result);
|
|
|
01add4 |
return NULL;
|
|
|
01add4 |
+ }
|
|
|
01add4 |
|
|
|
01add4 |
return (PyObject *)result;
|
|
|
01add4 |
}
|
|
|
01add4 |
diff --git a/satyr.c b/satyr.c
|
|
|
01add4 |
index 6e1ed28..44bf869 100644
|
|
|
01add4 |
--- a/satyr.c
|
|
|
01add4 |
+++ b/satyr.c
|
|
|
01add4 |
@@ -210,6 +210,9 @@ debug_normalize(int argc, char **argv)
|
|
|
01add4 |
struct sr_strbuf *strbuf = sr_strbuf_new();
|
|
|
01add4 |
sr_gdb_thread_append_to_str(thread, strbuf, false);
|
|
|
01add4 |
puts(strbuf->buf);
|
|
|
01add4 |
+
|
|
|
01add4 |
+ free(text);
|
|
|
01add4 |
+ sr_strbuf_free(strbuf);
|
|
|
01add4 |
}
|
|
|
01add4 |
|
|
|
01add4 |
static void
|
|
|
01add4 |
--
|
|
|
01add4 |
1.8.3.1
|
|
|
01add4 |
|