src/strutil.c (_str_convert): fixed memory leak: don't get error of valid

byte sequence conversion. Small optimization. Removed redundant code.
This commit is contained in:
Andrew Borodin 2009-04-29 20:35:42 +04:00
parent a93716386c
commit 4c5c8d4247
1 changed files with 10 additions and 18 deletions

View File

@ -141,15 +141,18 @@ _str_convert (GIConv coder, const char *string, int size, GString * buffer)
&bytes_written, &error); &bytes_written, &error);
if (error) if (error)
{ {
switch (error->code) int code = error->code;
g_error_free (error);
error = NULL;
switch (code)
{ {
case G_CONVERT_ERROR_NO_CONVERSION: case G_CONVERT_ERROR_NO_CONVERSION:
/* Conversion between the requested character sets is not supported. */ /* Conversion between the requested character sets is not supported. */
tmp_buff = g_strnfill (strlen (string), '?'); tmp_buff = g_strnfill (strlen (string), '?');
g_string_append (buffer, tmp_buff); g_string_append (buffer, tmp_buff);
g_free (tmp_buff); g_free (tmp_buff);
g_error_free (error);
error = NULL;
return ESTR_FAILURE; return ESTR_FAILURE;
case G_CONVERT_ERROR_ILLEGAL_SEQUENCE: case G_CONVERT_ERROR_ILLEGAL_SEQUENCE:
@ -158,10 +161,10 @@ _str_convert (GIConv coder, const char *string, int size, GString * buffer)
/* recode valid byte sequence */ /* recode valid byte sequence */
tmp_buff = g_convert_with_iconv ((const gchar *) string, tmp_buff = g_convert_with_iconv ((const gchar *) string,
bytes_read, bytes_read,
coder, coder, NULL, NULL, NULL);
NULL, NULL, &error);
if (tmp_buff != NULL) { if (tmp_buff != NULL)
{
g_string_append (buffer, tmp_buff); g_string_append (buffer, tmp_buff);
g_free (tmp_buff); g_free (tmp_buff);
} }
@ -175,8 +178,6 @@ _str_convert (GIConv coder, const char *string, int size, GString * buffer)
} }
else else
{ {
g_error_free (error);
error = NULL;
return ESTR_PROBLEM; return ESTR_PROBLEM;
} }
state = ESTR_PROBLEM; state = ESTR_PROBLEM;
@ -184,8 +185,6 @@ _str_convert (GIConv coder, const char *string, int size, GString * buffer)
case G_CONVERT_ERROR_PARTIAL_INPUT: case G_CONVERT_ERROR_PARTIAL_INPUT:
/* Partial character sequence at end of input. */ /* Partial character sequence at end of input. */
g_error_free (error);
error = NULL;
g_string_append (buffer, tmp_buff); g_string_append (buffer, tmp_buff);
g_free (tmp_buff); g_free (tmp_buff);
if ((int)bytes_read < left) if ((int)bytes_read < left)
@ -201,16 +200,9 @@ _str_convert (GIConv coder, const char *string, int size, GString * buffer)
case G_CONVERT_ERROR_NOT_ABSOLUTE_PATH: /* Don't know how handle this error :( */ case G_CONVERT_ERROR_NOT_ABSOLUTE_PATH: /* Don't know how handle this error :( */
case G_CONVERT_ERROR_FAILED: /* Conversion failed for some reason. */ case G_CONVERT_ERROR_FAILED: /* Conversion failed for some reason. */
default: default:
g_error_free (error); g_free (tmp_buff);
error = NULL;
if (tmp_buff){
g_free (tmp_buff);
tmp_buff = NULL;
}
return ESTR_FAILURE; return ESTR_FAILURE;
} }
g_error_free (error);
error = NULL;
} }
else else
{ {