mirror of
https://github.com/davatorium/rofi.git
synced 2024-11-18 13:54:36 -05:00
Copy memory instead of mixing malloc and g_malloc'ed memories (and freeing them all with g_free)
This commit is contained in:
parent
5fb6ee1383
commit
77a0800ccf
4 changed files with 7 additions and 18 deletions
|
@ -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.
|
||||
*/
|
||||
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 );
|
||||
PangoAttrList *token_match_get_pango_attr ( GRegex **tokens, const char *input, PangoAttrList *retv );
|
||||
/*@}*/
|
||||
|
|
|
@ -92,11 +92,9 @@ static char **get_dmenu ( DmenuModePrivateData *pd, FILE *fd, unsigned int *leng
|
|||
data[l - 1] = '\0';
|
||||
l--;
|
||||
}
|
||||
data = rofi_force_utf8 ( data );
|
||||
char *utfstr = rofi_force_utf8 ( data, l );
|
||||
|
||||
retv[( *length )] = data;
|
||||
data = NULL;
|
||||
data_l = 0;
|
||||
retv[( *length )] = utfstr;
|
||||
|
||||
( *length )++;
|
||||
// Stop when we hit 2³¹ entries.
|
||||
|
@ -529,6 +527,8 @@ int dmenu_switcher_dialog ( void )
|
|||
}
|
||||
}
|
||||
tokenize_free ( tokens );
|
||||
dmenu_mode_free ( &dmenu_mode );
|
||||
g_free ( input );
|
||||
return TRUE;
|
||||
}
|
||||
// TODO remove
|
||||
|
|
|
@ -294,14 +294,6 @@ static client* window_client ( xcb_window_t win )
|
|||
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 );
|
||||
g_free ( attr );
|
||||
return c;
|
||||
|
|
|
@ -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 );
|
||||
}
|
||||
|
||||
char * rofi_force_utf8 ( gchar *start )
|
||||
char * rofi_force_utf8 ( gchar *start, ssize_t length )
|
||||
{
|
||||
if ( start == NULL ) {
|
||||
return NULL;
|
||||
}
|
||||
const char *data = start;
|
||||
const char *end;
|
||||
gsize length = strlen ( data );
|
||||
GString *string;
|
||||
|
||||
if ( g_utf8_validate ( data, length, &end ) ) {
|
||||
return start;
|
||||
return g_memdup ( start, length + 1 );
|
||||
}
|
||||
string = g_string_sized_new ( length + 16 );
|
||||
|
||||
|
@ -624,7 +623,5 @@ char * rofi_force_utf8 ( gchar *start )
|
|||
g_string_append_len ( string, data, length );
|
||||
}
|
||||
|
||||
// Free input string.
|
||||
g_free ( start );
|
||||
return g_string_free ( string, FALSE );
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue