diff options
author | Tomas Bzatek <tbzatek@redhat.com> | 2013-10-08 17:49:32 +0200 |
---|---|---|
committer | Tomas Bzatek <tbzatek@redhat.com> | 2013-10-09 12:25:09 +0200 |
commit | 703ebe4493b59397f30bc2ee124c0d9c76be57f5 (patch) | |
tree | b2783de32c5ad5d6d56d98742910644067a1e0fa | |
parent | afa5462903c7b2390f1539bee7b87a4ca6954db4 (diff) | |
download | openlmi-providers-703ebe4493b59397f30bc2ee124c0d9c76be57f5.tar.gz openlmi-providers-703ebe4493b59397f30bc2ee124c0d9c76be57f5.tar.xz openlmi-providers-703ebe4493b59397f30bc2ee124c0d9c76be57f5.zip |
parse_config: Don't reuse already initialized GError struct
Setting an error on top of an existing error is considered a programmer's
bug, possibly leaking memory. So do proper cleanup before reusing that
variable.
Also, errors set while retrieving keys and values are not checked anywhere
so let's just don't set them. Returned NULL values in case of error should
be enough to skip the particular value.
-rw-r--r-- | src/openlmi.c | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/src/openlmi.c b/src/openlmi.c index 25cf57c..b991f6a 100644 --- a/src/openlmi.c +++ b/src/openlmi.c @@ -170,6 +170,7 @@ GKeyFile *parse_config(const char *provider_name, const ConfigEntry *provider_co // Read top-level openlmi configuration if (!g_key_file_load_from_file(masterKeyFile, TOPLEVEL_CONFIG_FILE, G_KEY_FILE_NONE, &error)) { lmi_debug("Can't read openlmi top-level config file %s: %s", TOPLEVEL_CONFIG_FILE, error->message); + g_clear_error(&error); } // Read provider-specific configuration @@ -186,6 +187,7 @@ GKeyFile *parse_config(const char *provider_name, const ConfigEntry *provider_co } if (!g_key_file_load_from_file(providerKeyFile, providerconf, G_KEY_FILE_NONE, &error)) { lmi_debug("Can't read provider specific config file %s: %s", providerconf, error->message); + g_clear_error(&error); } // Merge provider config to _masterKeyFile @@ -194,9 +196,9 @@ GKeyFile *parse_config(const char *provider_name, const ConfigEntry *provider_co gchar **groups = g_key_file_get_groups(providerKeyFile, &groups_len), **keys; if (groups != NULL) { for (i = 0; i < groups_len; ++i) { - keys = g_key_file_get_keys(providerKeyFile, groups[i], &keys_len, &error); + keys = g_key_file_get_keys(providerKeyFile, groups[i], &keys_len, NULL); for (j = 0; j < keys_len; ++j) { - v = g_key_file_get_value(providerKeyFile, groups[i], keys[j], &error); + v = g_key_file_get_value(providerKeyFile, groups[i], keys[j], NULL); g_key_file_set_value(masterKeyFile, groups[i], keys[j], v); free(v); } |