info: only open log file when adding it to the log function

This avoids the leak of opening it and then not passing it or closing it
before it goes out of scope.
This commit is contained in:
Luis de Bethencourt 2016-03-31 11:46:03 +01:00
parent c32ea3cb58
commit 1bb699446a

View file

@ -299,20 +299,24 @@ _priv_gst_debug_init (void)
const gchar *env; const gchar *env;
FILE *log_file; FILE *log_file;
env = g_getenv ("GST_DEBUG_FILE"); if (add_default_log_func) {
if (env != NULL && *env != '\0') { env = g_getenv ("GST_DEBUG_FILE");
if (strcmp (env, "-") == 0) { if (env != NULL && *env != '\0') {
log_file = stdout; if (strcmp (env, "-") == 0) {
} else { log_file = stdout;
log_file = g_fopen (env, "w"); } else {
if (log_file == NULL) { log_file = g_fopen (env, "w");
g_printerr ("Could not open log file '%s' for writing: %s\n", env, if (log_file == NULL) {
g_strerror (errno)); g_printerr ("Could not open log file '%s' for writing: %s\n", env,
log_file = stderr; g_strerror (errno));
log_file = stderr;
}
} }
} else {
log_file = stderr;
} }
} else {
log_file = stderr; gst_debug_add_log_function (gst_debug_log_default, log_file, NULL);
} }
__gst_printf_pointer_extension_set_func __gst_printf_pointer_extension_set_func
@ -324,9 +328,6 @@ _priv_gst_debug_init (void)
_GST_CAT_DEBUG = _gst_debug_category_new ("GST_DEBUG", _GST_CAT_DEBUG = _gst_debug_category_new ("GST_DEBUG",
GST_DEBUG_BOLD | GST_DEBUG_FG_YELLOW, "debugging subsystem"); GST_DEBUG_BOLD | GST_DEBUG_FG_YELLOW, "debugging subsystem");
if (add_default_log_func)
gst_debug_add_log_function (gst_debug_log_default, log_file, NULL);
/* FIXME: add descriptions here */ /* FIXME: add descriptions here */
GST_CAT_GST_INIT = _gst_debug_category_new ("GST_INIT", GST_CAT_GST_INIT = _gst_debug_category_new ("GST_INIT",
GST_DEBUG_BOLD | GST_DEBUG_FG_RED, NULL); GST_DEBUG_BOLD | GST_DEBUG_FG_RED, NULL);