[gobject-introspection] giscanner: Improve error handling while parsing macros
- From: Emmanuele Bassi <ebassi src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gobject-introspection] giscanner: Improve error handling while parsing macros
- Date: Sun, 20 Jun 2021 21:25:46 +0000 (UTC)
commit 3cab01728bc9035ebcc1f67c3b4ef8d884ed1c1f
Author: David King <dking redhat com>
Date: Thu May 20 13:47:46 2021 +0100
giscanner: Improve error handling while parsing macros
Check for errors during g_file_open_tmp() and fdopen(). Make sure to
free tmp_name and error as needed.
Found with Coverity.
https://bugzilla.redhat.com/show_bug.cgi?id=1938731
giscanner/scannerparser.y | 32 +++++++++++++++++++++++++++++---
1 file changed, 29 insertions(+), 3 deletions(-)
---
diff --git a/giscanner/scannerparser.y b/giscanner/scannerparser.y
index 269a7bd3..b304a298 100644
--- a/giscanner/scannerparser.y
+++ b/giscanner/scannerparser.y
@@ -1677,11 +1677,36 @@ gi_source_scanner_parse_macros (GISourceScanner *scanner, GList *filenames)
{
GError *error = NULL;
char *tmp_name = NULL;
- FILE *fmacros =
- fdopen (g_file_open_tmp ("gen-introspect-XXXXXX.h", &tmp_name, &error),
- "w+");
+ gint tmp_fd;
+ FILE *fmacros;
GList *l;
+ tmp_fd = g_file_open_tmp ("gen-introspect-XXXXXX.h", &tmp_name, &error);
+
+ if (tmp_fd == -1)
+ {
+ gchar *filename = g_file_get_path (scanner->current_file);
+ gchar *error_msg = g_strdup_printf ("%s: failed to create temporary file '%s' while parsing macros:
%s", filename, tmp_name, error->message);
+ g_ptr_array_add (scanner->errors, error_msg);
+ g_free (filename);
+ g_error_free (error);
+ return;
+ }
+
+ fmacros = fdopen (tmp_fd, "w+");
+
+ if (!fmacros)
+ {
+ gchar *filename = g_file_get_path (scanner->current_file);
+ gchar *error_msg = g_strdup_printf ("%s: failed to open temporary file '%s' while parsing macros",
filename, tmp_name);
+ g_ptr_array_add (scanner->errors, error_msg);
+ g_free (filename);
+ close (tmp_fd);
+ g_unlink (tmp_name);
+ g_free (tmp_name);
+ return;
+ }
+
for (l = filenames; l != NULL; l = l->next)
{
FILE *f = fopen (l->data, "r");
@@ -1821,6 +1846,7 @@ gi_source_scanner_parse_macros (GISourceScanner *scanner, GList *filenames)
parse_file (scanner, fmacros);
fclose (fmacros);
g_unlink (tmp_name);
+ g_free (tmp_name);
}
gboolean
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]