1
0
Fork 0
mirror of https://github.com/davatorium/rofi.git synced 2024-11-18 13:54:36 -05:00

Fix memory leak in box and listview widget, add coverage make target. (ggcov and lcov)

This commit is contained in:
Dave Davenport 2016-10-18 13:49:24 +02:00
parent 2c0c3c675a
commit 7b3b68462e
12 changed files with 46 additions and 25 deletions

View file

@ -348,5 +348,14 @@ $(top_builddir)/gitconfig.h: .FORCE
$(rofi_SOURCES): $(top_builddir)/gitconfig.h $(rofi_SOURCES): $(top_builddir)/gitconfig.h
.PHONY: coverage
coverage: coverage/index.html
coverage.info: $(top_builddir)/test/*.gcda $(top_builddir)/source/*.gcda $(top_builddir)/source/**/*.gcda
lcov --capture --directory ./ --output-file coverage.info
coverage/index.html: coverage.info
genhtml $^ --output-directory coverage/
.PHONY: .FORCE .PHONY: .FORCE
.FORCE: .FORCE:

View file

@ -46,16 +46,16 @@ typedef struct
*/ */
typedef enum typedef enum
{ {
TB_AUTOHEIGHT = 1 << 0, TB_AUTOHEIGHT = 1 << 0,
TB_AUTOWIDTH = 1 << 1, TB_AUTOWIDTH = 1 << 1,
TB_LEFT = 1 << 16, TB_LEFT = 1 << 16,
TB_RIGHT = 1 << 17, TB_RIGHT = 1 << 17,
TB_CENTER = 1 << 18, TB_CENTER = 1 << 18,
TB_EDITABLE = 1 << 19, TB_EDITABLE = 1 << 19,
TB_MARKUP = 1 << 20, TB_MARKUP = 1 << 20,
TB_WRAP = 1 << 21, TB_WRAP = 1 << 21,
TB_PASSWORD = 1 << 22, TB_PASSWORD = 1 << 22,
TB_INDICATOR = 1 << 23, TB_INDICATOR = 1 << 23,
} TextboxFlags; } TextboxFlags;
/** /**
* Flags indicating current state of the textbox. * Flags indicating current state of the textbox.

View file

@ -28,7 +28,7 @@ typedef struct _widget widget;
typedef gboolean ( *widget_clicked_cb )( widget *, xcb_button_press_event_t *, void * ); typedef gboolean ( *widget_clicked_cb )( widget *, xcb_button_press_event_t *, void * );
/** Macro to get widget from an implementation (e.g. textbox/scrollbar) */ /** Macro to get widget from an implementation (e.g. textbox/scrollbar) */
#define WIDGET( a ) ( ( a ) != NULL ? (widget *) ( a ) : NULL ) #define WIDGET( a ) ( (widget *) ( a ) )
/** /**
* @param widget The widget to check * @param widget The widget to check

View file

@ -366,7 +366,7 @@ static void walk_dir ( DRunModePrivateData *pd, const char *root, const char *di
} }
// Skip files not ending on .desktop. // Skip files not ending on .desktop.
if ( file->d_type != DT_DIR && !g_str_has_suffix ( file->d_name, ".desktop" ) ) { if ( file->d_type != DT_DIR && !g_str_has_suffix ( file->d_name, ".desktop" ) ) {
g_free(filename); g_free ( filename );
continue; continue;
} }

View file

@ -198,7 +198,7 @@ static char **read_hosts_file ( char ** retv, unsigned int *length )
// Reading one line per time. // Reading one line per time.
while ( getline ( &buffer, &buffer_length, fd ) > 0 ) { while ( getline ( &buffer, &buffer_length, fd ) > 0 ) {
// Evaluate one line. // Evaluate one line.
unsigned int index = 0, ti = 0; unsigned int index = 0, ti = 0;
char *token = buffer; char *token = buffer;
// Tokenize it. // Tokenize it.

View file

@ -194,7 +194,7 @@ static GRegex * create_regex ( const char *input, int case_sensitive )
{ {
#define R( s ) g_regex_new ( s, G_REGEX_OPTIMIZE | ( ( case_sensitive ) ? 0 : G_REGEX_CASELESS ), 0, NULL ) #define R( s ) g_regex_new ( s, G_REGEX_OPTIMIZE | ( ( case_sensitive ) ? 0 : G_REGEX_CASELESS ), 0, NULL )
GRegex * retv = NULL; GRegex * retv = NULL;
gchar *r; gchar *r;
switch ( config.matching_method ) switch ( config.matching_method )
{ {
case MM_GLOB: case MM_GLOB:
@ -234,7 +234,7 @@ GRegex **tokenize ( const char *input, int case_sensitive )
} }
char *saveptr = NULL, *token; char *saveptr = NULL, *token;
GRegex **retv = NULL; GRegex **retv = NULL;
if ( !config.tokenize ) { if ( !config.tokenize ) {
retv = g_malloc0 ( sizeof ( GRegex* ) * 2 ); retv = g_malloc0 ( sizeof ( GRegex* ) * 2 );
retv[0] = (GRegex *) create_regex ( input, case_sensitive ); retv[0] = (GRegex *) create_regex ( input, case_sensitive );

View file

@ -344,7 +344,7 @@ static int add_mode ( const char * token )
} }
else else
#endif // WINDOW_MODE #endif // WINDOW_MODE
// SSh dialog // SSh dialog
if ( strcasecmp ( token, "ssh" ) == 0 ) { if ( strcasecmp ( token, "ssh" ) == 0 ) {
modi[num_modi] = &ssh_mode; modi[num_modi] = &ssh_mode;
num_modi++; num_modi++;

View file

@ -202,13 +202,15 @@ static void box_free ( widget *wid )
widget * child = (widget *) iter->data; widget * child = (widget *) iter->data;
widget_free ( child ); widget_free ( child );
} }
g_list_free ( b->children );
g_free ( b ); g_free ( b );
} }
void box_add ( box *box, widget *child, gboolean expand, gboolean end ) void box_add ( box *box, widget *child, gboolean expand, gboolean end )
{ {
if ( box == NULL ) return; if ( box == NULL ) {
return;
}
child->expand = expand; child->expand = expand;
child->end = end; child->end = end;
child->parent = WIDGET ( box ); child->parent = WIDGET ( box );

View file

@ -71,9 +71,15 @@ struct _listview
void *mouse_activated_data; void *mouse_activated_data;
}; };
static void listview_free ( widget *widget ) static void listview_free ( widget *wid )
{ {
listview *lv = (listview *) widget; listview *lv = (listview *) wid;
for ( unsigned int i = 0; i < lv->cur_elements; i++ ) {
widget_free ( WIDGET ( lv->boxes [i] ) );
}
g_free ( lv->boxes );
widget_free ( WIDGET ( lv->scrollbar ) );
g_free ( lv ); g_free ( lv );
} }
static unsigned int scroll_per_page ( listview * lv ) static unsigned int scroll_per_page ( listview * lv )
@ -237,7 +243,7 @@ static void listview_resize ( widget *wid, short w, short h )
lv->max_rows = ( lv->padding + lv->widget.h ) / ( lv->element_height + lv->padding ); lv->max_rows = ( lv->padding + lv->widget.h ) / ( lv->element_height + lv->padding );
lv->max_elements = lv->max_rows * lv->menu_columns; lv->max_elements = lv->max_rows * lv->menu_columns;
widget_move ( WIDGET ( lv->scrollbar ), lv->widget.w - widget_get_width ( WIDGET (lv->scrollbar ) ), 0 ); widget_move ( WIDGET ( lv->scrollbar ), lv->widget.w - widget_get_width ( WIDGET ( lv->scrollbar ) ), 0 );
widget_resize ( WIDGET ( lv->scrollbar ), widget_get_width ( WIDGET ( lv->scrollbar ) ), h ); widget_resize ( WIDGET ( lv->scrollbar ), widget_get_width ( WIDGET ( lv->scrollbar ) ), h );
listview_recompute_elements ( lv ); listview_recompute_elements ( lv );

View file

@ -66,10 +66,10 @@ void widget_draw ( widget *widget, cairo_t *d )
widget->need_redraw = FALSE; widget->need_redraw = FALSE;
} }
} }
void widget_free ( widget *widget ) void widget_free ( widget *wid )
{ {
if ( widget && widget->free ) { if ( wid && wid->free ) {
widget->free ( widget ); wid->free ( wid );
} }
} }

View file

@ -197,7 +197,7 @@ static XrmOption xrmOptions[] = {
}; };
/** Dynamic array of extra options */ /** Dynamic array of extra options */
XrmOption *extra_options = NULL; XrmOption *extra_options = NULL;
/** Number of entries in extra options array */ /** Number of entries in extra options array */
unsigned int num_extra_options = 0; unsigned int num_extra_options = 0;

View file

@ -20,6 +20,10 @@ int main ( G_GNUC_UNUSED int argc, G_GNUC_UNUSED char **argv )
widget *wid= (widget*)g_malloc0(sizeof(widget)); widget *wid= (widget*)g_malloc0(sizeof(widget));
widget_resize ( wid, 20, 40); widget_resize ( wid, 20, 40);
widget_move ( wid, 10, 10); widget_move ( wid, 10, 10);
// Getter, setter x pos
//
TASSERT( widget_get_x_pos ( wid ) == 10 );
TASSERT( widget_get_y_pos ( wid ) == 10 );
// Left of box // Left of box
TASSERT ( widget_intersect ( wid, 0, 0) == 0 ); TASSERT ( widget_intersect ( wid, 0, 0) == 0 );