summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDave Davenport <qball@gmpclient.org>2016-06-21 22:40:42 +0200
committerDave Davenport <qball@gmpclient.org>2016-06-21 22:40:42 +0200
commit77a0800ccf6e76b0c843e5f01eba6d447dd57463 (patch)
tree81db7faa4351421c0ad040d42fa9088b74456d7b
parent5fb6ee1383ff21cfc6c46cc0514c6c86dd297c03 (diff)
Copy memory instead of mixing malloc and g_malloc'ed memories (and freeing them all with g_free)
-rw-r--r--include/helper.h2
-rw-r--r--source/dialogs/dmenu.c8
-rw-r--r--source/dialogs/window.c8
-rw-r--r--source/helper.c7
4 files changed, 7 insertions, 18 deletions
diff --git a/include/helper.h b/include/helper.h
index 81cd330c..e337bf39 100644
--- a/include/helper.h
+++ b/include/helper.h
@@ -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 );
/*@}*/
diff --git a/source/dialogs/dmenu.c b/source/dialogs/dmenu.c
index c7b016aa..887e6a42 100644
--- a/source/dialogs/dmenu.c
+++ b/source/dialogs/dmenu.c
@@ -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
diff --git a/source/dialogs/window.c b/source/dialogs/window.c
index d56e76f0..a931fdbf 100644
--- a/source/dialogs/window.c
+++ b/source/dialogs/window.c
@@ -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;
diff --git a/source/helper.c b/source/helper.c
index e2c9b2f0..4c0f5bca 100644
--- a/source/helper.c
+++ b/source/helper.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 );
}