On Wed, 2010-12-01 at 14:59 +0100, Nikola Pajkovsky wrote:
static void get_reporter_plugin_settings(const vector_string_t& reporters, map_map_string_t &settings)
a new interface is
static GHashTable *get_reporter_plugin_settings(const vector_string_t& reporters)
Signed-off-by: Nikola Pajkovsky npajkovs@redhat.com
src/cli/dbus.cpp | 6 ++-- src/cli/dbus.h | 3 +- src/cli/report.cpp | 65 +++++++++++++++++++++++++++++++++++++------------- src/lib/abrt_dbus.h | 29 ++++++++++++++++++++++ 4 files changed, 82 insertions(+), 21 deletions(-)
diff --git a/src/cli/report.cpp b/src/cli/report.cpp index 78a3891..ff953b2 100644 --- a/src/cli/report.cpp +++ b/src/cli/report.cpp @@ -503,23 +503,49 @@ static bool set_echo(bool enabled) }
/**
- Destroy plugin settings
- @param ht
Plugin settings in pattern GHashTable<char *, map_string_t *>
- */
+static void destroy_plugin_settings(GHashTable *ht)
I would call it destroy_GHashTable_map_string_t() or maybe free_GHashTable_map_string_t().
*/ -static void get_reporter_plugin_settings(const vector_string_t& reporters,
map_map_string_t &settings)
+static GHashTable *get_reporter_plugin_settings(const vector_string_t& reporters) { /* First of all, load system-wide report plugin settings. */
- GHashTable *settings = g_hash_table_new(g_str_hash, g_str_equal);
Alternatively, you may want to use g_hash_table_new_full here http://library.gnome.org/devel/glib/stable/glib-Hash-Tables.html#g-hash-tabl... - it allows "freeing" functions to be remembered in created GHashTable. I think it means that simple g_hash_table_destroy() will be able to fully free the created GHashTable.
for (vector_string_t::const_iterator it = reporters.begin(); it != reporters.end(); ++it) {
map_string_t single_plugin_settings = call_GetPluginSettings(it->c_str());
map_string_t *single_plugin_settings = new map_string_t;
*single_plugin_settings = call_GetPluginSettings(it->c_str());
// Copy the received settings as defaults. // Plugins won't work without it, if some value is missing // they use their default values for all fields.
settings[it->c_str()] = single_plugin_settings;
g_hash_table_insert(settings, xstrdup(it->c_str()), (void*)single_plugin_settings);
Here, if key already exists, it (and corresponding value) needs to be properly freed. This won't happen if you created GHashTable with simple g_hash_table_new - the key and value will leak.
while (g_hash_table_iter_next (&iter, &key, &value)) { map_string_t single_plugin_settings; std::string path = std::string(homedir) + "/.abrt/"
+ it->first + ".conf";
+ (char*)key + ".conf";
You may also get rid of this C++ism (convert it to xasprintf) while you are at it.