From 1718c53c1125eb6b0d84b35cf761ec7672f2998a Mon Sep 17 00:00:00 2001
From: Alexandre Savard <alexandre.savard@savoirfairelinux.com>
Date: Mon, 20 Sep 2010 17:01:47 -0400
Subject: [PATCH] [#4107] Do not call yaml_document_delete after
 yaml_emitter_dump

---
 sflphone-common/src/config/yamlemitter.cpp | 24 +++++++++++++---------
 sflphone-common/src/config/yamlparser.cpp  |  6 +++---
 sflphone-common/src/managerimpl.cpp        |  2 ++
 3 files changed, 19 insertions(+), 13 deletions(-)

diff --git a/sflphone-common/src/config/yamlemitter.cpp b/sflphone-common/src/config/yamlemitter.cpp
index 3b6ba5c0c3..0f07f77753 100644
--- a/sflphone-common/src/config/yamlemitter.cpp
+++ b/sflphone-common/src/config/yamlemitter.cpp
@@ -47,7 +47,8 @@ YamlEmitter::~YamlEmitter()
 
 void YamlEmitter::open()
 {
-    fd = fopen (filename.c_str(), "wb");
+
+    fd = fopen (filename.c_str(), "w");
 
     if (!fd)
         throw YamlEmitterException ("Could not open file descriptor");
@@ -55,12 +56,13 @@ void YamlEmitter::open()
     if (!yaml_emitter_initialize (&emitter))
         throw YamlEmitterException ("Could not initialize emitter");
 
-    // Use unicode format
+    // Allows unescaped unicode characters
     yaml_emitter_set_unicode (&emitter, 1);
 
     yaml_emitter_set_output_file (&emitter, fd);
 
-    yaml_document_initialize (&document, NULL, NULL, NULL, 0, 0);
+    if (!yaml_document_initialize (&document, NULL, NULL, NULL, 0, 0))
+        throw YamlEmitterException ("Could not initialize yaml document while saving configuration");
 
     // Init the main configuration mapping
     if ( (topLevelMapping = yaml_document_add_mapping (&document, NULL, YAML_BLOCK_MAPPING_STYLE)) == 0)
@@ -74,13 +76,13 @@ void YamlEmitter::close()
     if (!fd)
         throw YamlEmitterException ("File descriptor not valid");
 
-    fclose (fd);
-    /*
-    if(!fclose(fd))
-      throw YamlEmitterException("Error closing file descriptor");
-    */
 
-    yaml_document_delete (&document);
+    if (fclose (fd))
+        throw YamlEmitterException ("Error closing file descriptor");
+
+
+    _debug ("Config: Configuration file closed successfully");
+
 }
 
 void YamlEmitter::read() {}
@@ -92,7 +94,9 @@ void YamlEmitter::write()
 
 void YamlEmitter::serializeData()
 {
-    yaml_emitter_dump (&emitter, &document);
+    // Document object is destroyed once its content is emitted
+    if (!yaml_emitter_dump (&emitter, &document))
+        throw YamlEmitterException ("Error while emitting configuration yaml document");
 }
 
 
diff --git a/sflphone-common/src/config/yamlparser.cpp b/sflphone-common/src/config/yamlparser.cpp
index b4d8c5de47..90b46c8470 100644
--- a/sflphone-common/src/config/yamlparser.cpp
+++ b/sflphone-common/src/config/yamlparser.cpp
@@ -79,9 +79,9 @@ void YamlParser::close()
     if (!fd)
         throw YamlParserException ("File descriptor not valid");
 
-    fclose (fd);
-    // if(!fclose(fd))
-    // throw YamlParserException("Error closing file descriptor");
+    // fclose (fd);
+    if (fclose (fd))
+        throw YamlParserException ("Error closing file descriptor");
 
 
 }
diff --git a/sflphone-common/src/managerimpl.cpp b/sflphone-common/src/managerimpl.cpp
index 5f48c1ae0d..8bbc44abbc 100644
--- a/sflphone-common/src/managerimpl.cpp
+++ b/sflphone-common/src/managerimpl.cpp
@@ -166,6 +166,8 @@ void ManagerImpl::init ()
 
     // Init the instant messaging module
     _imModule->init();
+
+
 }
 
 void ManagerImpl::terminate ()
-- 
GitLab