changeset 1265:cbc3174bed98

Fixed possible segfault during files on and debug on
author Jiri Vanek <jvanek@redhat.com>
date Fri, 02 Oct 2015 15:35:30 +0200
parents 75504136acda
children 2b1af623e3a8
files ChangeLog plugin/icedteanp/IcedTeaNPPlugin.cc plugin/icedteanp/IcedTeaNPPlugin.h plugin/icedteanp/IcedTeaPluginUtils.h
diffstat 4 files changed, 16 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Tue Sep 22 18:24:33 2015 +0200
+++ b/ChangeLog	Fri Oct 02 15:35:30 2015 +0200
@@ -1,3 +1,13 @@
+2015-10-02  Jiri Vanek  <jvanek@redhat.com>
+
+	Fixed possible segfault during files on and debug on
+	* plugin/icedteanp/IcedTeaNPPlugin.cc: added file_logs_initiated initiated as
+	false. plugin_file_log initiated to NULL.
+	* plugin/icedteanp/IcedTeaNPPlugin.h: made aware about extern file_logs_initiated
+	* plugin/icedteanp/IcedTeaPluginUtils.h: (initialize_debug) set file_logs_initiated
+	to true after initFileLog finishes. (PLUGIN_DEBUG) and (PLUGIN_ERROR) logs to
+	file only when enabled and initiated.
+
 2015-09-22  Jiri Vanek  <jvanek@redhat.com>
 
 	fixed two doclint errors
--- a/plugin/icedteanp/IcedTeaNPPlugin.cc	Tue Sep 22 18:24:33 2015 +0200
+++ b/plugin/icedteanp/IcedTeaNPPlugin.cc	Fri Oct 02 15:35:30 2015 +0200
@@ -241,13 +241,14 @@
 static guint appletviewer_watch_id = -1;
 
 bool debug_initiated = false;
+bool file_logs_initiated = false;
 int plugin_debug = getenv ("ICEDTEAPLUGIN_DEBUG") != NULL;
 bool plugin_debug_headers = false;
 bool plugin_debug_to_file = false ;
 bool plugin_debug_to_streams = true ;
 bool plugin_debug_to_system = false;
 bool plugin_debug_to_console = true;
-FILE *  plugin_file_log;
+FILE *  plugin_file_log = NULL;
 std::string plugin_file_log_name;
 
 int plugin_debug_suspend = (getenv("ICEDTEAPLUGIN_DEBUG") != NULL) &&
--- a/plugin/icedteanp/IcedTeaNPPlugin.h	Tue Sep 22 18:24:33 2015 +0200
+++ b/plugin/icedteanp/IcedTeaNPPlugin.h	Fri Oct 02 15:35:30 2015 +0200
@@ -117,6 +117,7 @@
 
 // debug switches
 extern bool debug_initiated;
+extern bool file_logs_initiated;
 extern int plugin_debug;
 extern bool plugin_debug_headers;
 extern bool plugin_debug_to_file;
--- a/plugin/icedteanp/IcedTeaPluginUtils.h	Tue Sep 22 18:24:33 2015 +0200
+++ b/plugin/icedteanp/IcedTeaPluginUtils.h	Fri Oct 02 15:35:30 2015 +0200
@@ -86,6 +86,7 @@
       plugin_debug_to_console = is_java_console_enabled();                    \
       if (plugin_debug_to_file) {                                             \
            IcedTeaPluginUtilities::initFileLog();                             \
+           file_logs_initiated = true;                                        \
       }                                                                       \
       if (plugin_debug_to_console) {                                          \
           /*initialisation done during jvm startup*/                          \
@@ -134,7 +135,7 @@
         snprintf(ldebug_message, MESSAGE_SIZE, "%s%s", ldebug_header, ldebug_body); \
         fprintf  (stdout, "%s", ldebug_message);\
       }                                \
-      if (plugin_debug_to_file) {      \
+      if (plugin_debug_to_file && file_logs_initiated) {      \
         snprintf(ldebug_message, MESSAGE_SIZE, "%s%s", ldebug_header, ldebug_body);   \
         fprintf (plugin_file_log, "%s", ldebug_message);   \
         fflush(plugin_file_log);       \
@@ -180,7 +181,7 @@
       snprintf(ldebug_message, MESSAGE_SIZE, "%s%s", ldebug_header, ldebug_body); \
       fprintf  (stderr, "%s", ldebug_message);                                    \
     }                                  \
-    if (plugin_debug_to_file) {        \
+    if (plugin_debug_to_file && file_logs_initiated) {        \
       snprintf(ldebug_message, MESSAGE_SIZE, "%s%s", ldebug_header, ldebug_body); \
       fprintf (plugin_file_log, "%s", ldebug_message);   \
       fflush(plugin_file_log);         \