1
0
Fork 0
mirror of https://github.com/davatorium/rofi.git synced 2025-07-31 21:59:25 -04:00

Copy memory instead of mixing malloc and g_malloc'ed memories (and freeing them all with g_free)

This commit is contained in:
Dave Davenport 2016-06-21 22:40:42 +02:00
parent 5fb6ee1383
commit 77a0800ccf
4 changed files with 7 additions and 18 deletions

View file

@ -158,7 +158,7 @@ unsigned int levenshtein ( const char *needle, const char *haystack );
/** /**
* Convert string to valid utf-8, replacing invalid parts with replacement character. * Convert string to valid utf-8, replacing invalid parts with replacement character.
*/ */
char * rofi_force_utf8 ( gchar *data ); char * rofi_force_utf8 ( gchar *data, ssize_t length );
char * rofi_latin_to_utf8_strdup ( const char *input, gssize length ); char * rofi_latin_to_utf8_strdup ( const char *input, gssize length );
PangoAttrList *token_match_get_pango_attr ( GRegex **tokens, const char *input, PangoAttrList *retv ); PangoAttrList *token_match_get_pango_attr ( GRegex **tokens, const char *input, PangoAttrList *retv );
/*@}*/ /*@}*/

View file

@ -92,11 +92,9 @@ static char **get_dmenu ( DmenuModePrivateData *pd, FILE *fd, unsigned int *leng
data[l - 1] = '\0'; data[l - 1] = '\0';
l--; l--;
} }
data = rofi_force_utf8 ( data ); char *utfstr = rofi_force_utf8 ( data, l );
retv[( *length )] = data; retv[( *length )] = utfstr;
data = NULL;
data_l = 0;
( *length )++; ( *length )++;
// Stop when we hit 2³¹ entries. // Stop when we hit 2³¹ entries.
@ -529,6 +527,8 @@ int dmenu_switcher_dialog ( void )
} }
} }
tokenize_free ( tokens ); tokenize_free ( tokens );
dmenu_mode_free ( &dmenu_mode );
g_free ( input );
return TRUE; return TRUE;
} }
// TODO remove // TODO remove

View file

@ -294,14 +294,6 @@ static client* window_client ( xcb_window_t win )
c->hint_flags = r.flags; c->hint_flags = r.flags;
} }
/** Do UTF-8 Check, should not be needed, does not hurt here to be paranoid. */
{
c->title = rofi_force_utf8 ( c->title );
c->class = rofi_force_utf8 ( c->class );
c->name = rofi_force_utf8 ( c->name );
c->role = rofi_force_utf8 ( c->role );
}
winlist_append ( cache_client, c->window, c ); winlist_append ( cache_client, c->window, c );
g_free ( attr ); g_free ( attr );
return c; return c;

View file

@ -596,18 +596,17 @@ char * rofi_latin_to_utf8_strdup ( const char *input, gssize length )
return g_convert_with_fallback ( input, length, "UTF-8", "latin1", "\uFFFD", NULL, &slength, NULL ); return g_convert_with_fallback ( input, length, "UTF-8", "latin1", "\uFFFD", NULL, &slength, NULL );
} }
char * rofi_force_utf8 ( gchar *start ) char * rofi_force_utf8 ( gchar *start, ssize_t length )
{ {
if ( start == NULL ) { if ( start == NULL ) {
return NULL; return NULL;
} }
const char *data = start; const char *data = start;
const char *end; const char *end;
gsize length = strlen ( data );
GString *string; GString *string;
if ( g_utf8_validate ( data, length, &end ) ) { if ( g_utf8_validate ( data, length, &end ) ) {
return start; return g_memdup ( start, length + 1 );
} }
string = g_string_sized_new ( length + 16 ); string = g_string_sized_new ( length + 16 );
@ -624,7 +623,5 @@ char * rofi_force_utf8 ( gchar *start )
g_string_append_len ( string, data, length ); g_string_append_len ( string, data, length );
} }
// Free input string.
g_free ( start );
return g_string_free ( string, FALSE ); return g_string_free ( string, FALSE );
} }