summaryrefslogtreecommitdiffstats
path: root/src/lib
diff options
context:
space:
mode:
authorDenys Vlasenko <dvlasenk@redhat.com>2011-03-09 15:04:04 +0100
committerDenys Vlasenko <dvlasenk@redhat.com>2011-03-09 15:04:04 +0100
commit12afc6905e943f8f358a6e7adcbc7f06ae665787 (patch)
tree474244d224e65c0d9d8099046771147d2b5a1edd /src/lib
parent93b9b18b5096c7591c02036e1c908f3bcbb09f29 (diff)
downloadabrt-12afc6905e943f8f358a6e7adcbc7f06ae665787.tar.gz
abrt-12afc6905e943f8f358a6e7adcbc7f06ae665787.tar.xz
abrt-12afc6905e943f8f358a6e7adcbc7f06ae665787.zip
fix a leak in event_xml_parser.c; simplify load_conf_file() a bit
Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/event_xml_parser.c8
-rw-r--r--src/lib/load_plugin_settings.c52
2 files changed, 31 insertions, 29 deletions
diff --git a/src/lib/event_xml_parser.c b/src/lib/event_xml_parser.c
index a0e6c3c4..5f1974fd 100644
--- a/src/lib/event_xml_parser.c
+++ b/src/lib/event_xml_parser.c
@@ -135,13 +135,15 @@ static void text(GMarkupParseContext *context,
ui->name = _text;
return;
}
- if(strcmp(inner_element, DESCRIPTION_ELEMENT) == 0)
+ if (strcmp(inner_element, DESCRIPTION_ELEMENT) == 0)
{
VERB2 log("event description:'%s'", _text);
free(ui->description);
ui->description = _text;
+ return;
}
}
+ free(_text);
}
// Called for strings that should be re-saved verbatim in this same
@@ -186,11 +188,11 @@ void load_event_description_from_file(event_config_t *event_config, const char*
event_config, /*GDestroyNotify:*/ NULL);
FILE* fin = fopen(filename, "r");
- if(fin != NULL)
+ if (fin != NULL)
{
size_t read_bytes = 0;
char buff[1024];
- while ((read_bytes = fread(buff, 1, 1024, fin)))
+ while ((read_bytes = fread(buff, 1, 1024, fin)) != 0)
{
g_markup_parse_context_parse(context, buff, read_bytes, NULL);
}
diff --git a/src/lib/load_plugin_settings.c b/src/lib/load_plugin_settings.c
index 1e6b31e7..1b6086f9 100644
--- a/src/lib/load_plugin_settings.c
+++ b/src/lib/load_plugin_settings.c
@@ -34,47 +34,47 @@ bool load_conf_file(const char *pPath, map_string_h *settings, bool skipKeysWith
char *line;
while ((line = xmalloc_fgetline(fp)) != NULL)
{
- unsigned ii;
- bool valid = false;
bool in_quote = false;
/* We are reusing line buffer to form temporary
* "key\0value\0..." in its beginning
*/
- char *key = line;
- char *value = line;
- char *cur = line;
-
- for (ii = 0; line[ii] != '\0'; ii++)
+ char *value = NULL;
+ char *src;
+ char *dst;
+ for (src = dst = line; *src; src++)
{
- if (line[ii] == '"')
+ char c = *src;
+ if (c == '"')
{
in_quote = !in_quote;
}
- if (isspace(line[ii]) && !in_quote)
- {
- continue;
- }
- if (line[ii] == '#' && !in_quote && cur == line)
- {
- break;
- }
- if (line[ii] == '=' && !in_quote)
+ if (!in_quote)
{
- valid = true;
- *cur++ = '\0'; /* terminate key */
- value = cur; /* remember where value starts */
- continue;
+ if (isspace(c))
+ {
+ continue;
+ }
+ if (c == '#' && dst == line)
+ {
+ break;
+ }
+ if (c == '=')
+ {
+ *dst++ = '\0'; /* terminate key */
+ value = dst; /* remember where value starts */
+ continue;
+ }
}
- *cur++ = line[ii]; /* store next key or value char */
+ *dst++ = c; /* store next key or value char */
}
- *cur++ = '\0'; /* terminate value */
+ *dst = '\0'; /* terminate value */
/* Skip broken or empty lines. */
- if (!valid)
+ if (!value)
goto free_line;
/* Skip lines with empty key. */
- if (key[0] == '\0')
+ if (line[0] == '\0')
goto free_line;
if (skipKeysWithoutValue && value[0] == '\0')
@@ -84,7 +84,7 @@ bool load_conf_file(const char *pPath, map_string_h *settings, bool skipKeysWith
if (in_quote)
goto free_line;
- g_hash_table_replace(settings, xstrdup(key), xstrdup(value));
+ g_hash_table_replace(settings, xstrdup(line), xstrdup(value));
free_line:
free(line);
}