Fix a leak and a null pointer dereference

This commit is contained in:
Přemysl Eric Janouch 2015-02-22 21:30:30 +01:00
parent f468fdf343
commit f6f66c9021
1 changed files with 10 additions and 5 deletions

View File

@ -169,17 +169,20 @@ vprint_attributed (struct app_context *ctx,
if (!attribute) if (!attribute)
printer = NULL; printer = NULL;
const char *value; if (printer)
value = str_map_find (&ctx->config, attribute); {
if (printer && soft_assert (value)) const char *value = str_map_find (&ctx->config, attribute);
tputs (value, 1, printer); tputs (value, 1, printer);
}
vfprintf (stream, fmt, ap); vfprintf (stream, fmt, ap);
value = str_map_find (&ctx->config, ATTR_RESET); if (printer)
if (printer && soft_assert (value)) {
const char *value = str_map_find (&ctx->config, ATTR_RESET);
tputs (value, 1, printer); tputs (value, 1, printer);
} }
}
static void static void
print_attributed (struct app_context *ctx, print_attributed (struct app_context *ctx,
@ -465,6 +468,8 @@ parse_response (struct app_context *ctx, struct str *buf)
char *utf8 = xstrdup_printf ("error response: %" JSON_INTEGER_FORMAT char *utf8 = xstrdup_printf ("error response: %" JSON_INTEGER_FORMAT
" (%s)", code_val, json_string_value (message)); " (%s)", code_val, json_string_value (message));
char *s = iconv_xstrdup (ctx->term_from_utf8, utf8, -1, NULL); char *s = iconv_xstrdup (ctx->term_from_utf8, utf8, -1, NULL);
free (utf8);
if (!s) if (!s)
print_error ("character conversion failed for `%s'", "error"); print_error ("character conversion failed for `%s'", "error");
else else