Skip to content

Commit

Permalink
Fix minor memory leaks, and UB found by cppcheck
Browse files Browse the repository at this point in the history
  • Loading branch information
hellosiyan committed Nov 25, 2018
1 parent fe1fab6 commit 9160eaa
Show file tree
Hide file tree
Showing 12 changed files with 26 additions and 62 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ compile
libtool
*.desktop
.deps
.idea
builddir/

viewnior-*.tar.gz
*.sublime-project
Expand Down
14 changes: 0 additions & 14 deletions src/uni-anim-view.c
Original file line number Diff line number Diff line change
Expand Up @@ -337,17 +337,3 @@ uni_anim_view_set_is_playing (UniAnimView * aview, gboolean playing)
else if (playing && aview->anim)
uni_anim_view_updator (aview);
}

/**
* uni_anim_view_get_is_playing:
* @aview: A #UniImageView.
* @returns: %TRUE if an animation is playing, %FALSE otherwise.
*
* Returns whether the animation is playing or not. If there is no
* current animation, this method will always returns %FALSE.
**/
gboolean
uni_anim_view_get_is_playing (UniAnimView * aview)
{
return aview->timer_id && aview->anim;
}
3 changes: 1 addition & 2 deletions src/uni-anim-view.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
* Viewnior is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Viewnior is distributed in the hope that it will be useful,
Expand Down Expand Up @@ -82,7 +83,5 @@ void uni_anim_view_set_static (UniAnimView * aview,
void uni_anim_view_set_is_playing (UniAnimView * aview,
gboolean playing);

gboolean uni_anim_view_get_is_playing (UniAnimView * aview);

G_END_DECLS
#endif /* __UNI_ANIM_VIEW_H__ */
2 changes: 1 addition & 1 deletion src/uni-cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ uni_pixbuf_draw_cache_intersect_draw (UniPixbufDrawCache * cache,

/* If there is no intersection, we have to scale the whole area
from the source pixbuf. */
GdkRectangle inter;
GdkRectangle inter = {0, 0, 0, 0};
GdkRectangle around[4] = {
this,
{0, 0, 0, 0},
Expand Down
14 changes: 0 additions & 14 deletions src/uni-exiv2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,6 @@

static Exiv2::Image::AutoPtr cached_image;

extern "C"
void
uni_exif_dictionary_map(void (*callback)(const char*, const char*, void*), void *user_data)
{
uint i;
for( i=0; i<sizeof(exifDataDictionary)/sizeof(exifDataDictionary[0]); i++ ) {
callback(exifDataDictionary[i].key, exifDataDictionary[i].label, user_data);
}

for( i=0; i<sizeof(iptcDataDictionary)/sizeof(iptcDataDictionary[0]); i++ ) {
callback(iptcDataDictionary[i].key, iptcDataDictionary[i].label, user_data);
}
}

extern "C"
void
uni_read_exiv2_map(const char *uri, void (*callback)(const char*, const char*, void*), void *user_data)
Expand Down
2 changes: 0 additions & 2 deletions src/uni-exiv2.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,6 @@ extern "C" {

#endif /* __cplusplus */

void uni_exif_dictionary_map (void (*callback)(const char*, const char*, void*),
void *user_data);
void uni_read_exiv2_map (const char *uri,
void (*callback)(const char*, const char*, void*),
void *user_data);
Expand Down
4 changes: 2 additions & 2 deletions src/uni-image-view.c
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ uni_image_view_repaint_area (UniImageView * view, GdkRectangle * paint_rect)
view->is_rendering = TRUE;

// Image area is the area on the widget occupied by the pixbuf.
GdkRectangle image_area;
GdkRectangle image_area = {0, 0, 0, 0};
Size alloc = uni_image_view_get_allocated_size (view);
uni_image_view_get_draw_rect (view, &image_area);
if (image_area.x > 0 ||
Expand All @@ -267,7 +267,7 @@ uni_image_view_repaint_area (UniImageView * view, GdkRectangle * paint_rect)
GtkWidget *widget = GTK_WIDGET (view);

// Paint area is the area on the widget that should be redrawn.
GdkRectangle paint_area;
GdkRectangle paint_area = {0, 0, 0, 0};
gboolean intersects = gdk_rectangle_intersect (&image_area,
paint_rect,
&paint_area);
Expand Down
2 changes: 1 addition & 1 deletion src/uni-nav.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ uni_nav_get_zoom2nav_factor (UniNav * nav)
static GdkRectangle
gtk_image_get_current_rectangle (UniNav * nav)
{
GdkRectangle rect;
GdkRectangle rect = {0, 0, 0, 0};
uni_image_view_get_viewport (nav->view, &rect);

/* Convert Zoom space to Nav space coordinates. */
Expand Down
18 changes: 6 additions & 12 deletions src/vnr-file.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,14 @@ static GList *
vnr_file_get_supported_mime_types (void)
{
GSList *format_list, *it;
gchar **mime_types;
int i;

if (!supported_mime_types) {
format_list = gdk_pixbuf_get_formats ();

for (it = format_list; it != NULL; it = it->next) {
mime_types =
gdk_pixbuf_format_get_mime_types ((GdkPixbufFormat *) it->data);
gchar **mime_types = gdk_pixbuf_format_get_mime_types((GdkPixbufFormat *) it->data);

int i;
for (i = 0; mime_types[i] != NULL; i++) {
supported_mime_types =
g_list_prepend (supported_mime_types,
Expand Down Expand Up @@ -136,8 +134,6 @@ vnr_file_dir_content_to_list(gchar *path, gboolean sort, gboolean include_hidden
GFile *file;
GFileEnumerator *f_enum ;
GFileInfo *file_info;
VnrFile *vnr_file;
const char *mimetype;

file = g_file_new_for_path(path);
f_enum = g_file_enumerate_children(file, G_FILE_ATTRIBUTE_STANDARD_NAME","
Expand All @@ -150,9 +146,9 @@ vnr_file_dir_content_to_list(gchar *path, gboolean sort, gboolean include_hidden


while(file_info != NULL){
vnr_file = vnr_file_new();
VnrFile *vnr_file = vnr_file_new();

mimetype =g_file_info_get_content_type(file_info);
const char *mimetype =g_file_info_get_content_type(file_info);

if(vnr_file_is_supported_mime_type(mimetype) && (include_hidden || !g_file_info_get_is_hidden (file_info)) ){
vnr_file_set_display_name(vnr_file, (char*)g_file_info_get_display_name (file_info));
Expand Down Expand Up @@ -232,16 +228,14 @@ vnr_file_load_single_uri(char *p_path, GList **file_list, gboolean include_hidde
void
vnr_file_load_uri_list (GSList *uri_list, GList **file_list, gboolean include_hidden, GError **error)
{
GFile *file;
GFileInfo *fileinfo;
GFileType filetype;
gchar *p_path;

while(uri_list != NULL)
{
p_path = uri_list->data;
file = g_file_new_for_path(p_path);
fileinfo = g_file_query_info (file, G_FILE_ATTRIBUTE_STANDARD_TYPE","
GFile *file = g_file_new_for_path(p_path);
GFileInfo *fileinfo = g_file_query_info (file, G_FILE_ATTRIBUTE_STANDARD_TYPE","
G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME","
G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE","
G_FILE_ATTRIBUTE_STANDARD_IS_HIDDEN,
Expand Down
4 changes: 3 additions & 1 deletion src/vnr-prefs.c
Original file line number Diff line number Diff line change
Expand Up @@ -472,8 +472,10 @@ vnr_prefs_save (VnrPrefs *prefs)

if(rcfile != NULL)
{
fputs(g_key_file_to_data (conf, NULL, NULL), rcfile);
gchar *data = g_key_file_to_data (conf, NULL, NULL);
fputs(data, rcfile);
fclose(rcfile);
g_free(data);
}
else
g_warning("Saving config file: Unable to open the configuration file for writing!\n");
Expand Down
3 changes: 1 addition & 2 deletions src/vnr-tools.c
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,11 @@ vnr_tools_parse_uri_string_list_to_file_list (const gchar *uri_list)
GSList* file_list = NULL;
gsize i = 0;
gchar **uris;
gchar* current_path;

uris = g_uri_list_extract_uris (uri_list);

while (uris[i] != NULL) {
current_path = g_file_get_path (g_file_new_for_uri(uris[i]));
gchar* current_path = g_file_get_path (g_file_new_for_uri(uris[i]));
if(current_path != NULL)
file_list = g_slist_append (file_list, current_path);
i++;
Expand Down
20 changes: 9 additions & 11 deletions src/vnr-window.c
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ update_fs_filename_label(VnrWindow *window)
return;

gint position, total;
char *buf = NULL;
char *buf;

get_position_of_element_in_list(window->file_list, &position, &total);
buf = g_strdup_printf ("%s - %i/%i",
Expand Down Expand Up @@ -1141,10 +1141,10 @@ file_open_dialog_response_cb (GtkWidget *dialog,
{
if (response_id == GTK_RESPONSE_ACCEPT)
{
GSList *uri_list = NULL;
uri_list = gtk_file_chooser_get_filenames (GTK_FILE_CHOOSER (dialog));
GSList *uri_list = gtk_file_chooser_get_filenames (GTK_FILE_CHOOSER (dialog));
g_return_if_fail(uri_list != NULL);
vnr_window_open_from_list(window, uri_list);
g_slist_free_full(uri_list, g_free);
}

gtk_widget_destroy (dialog);
Expand Down Expand Up @@ -1312,8 +1312,8 @@ vnr_window_cmd_open(GtkAction *action, VnrWindow *window)
{
GtkWidget *dialog;
GtkWidget *preview;
GtkFileFilter *img_filter = NULL;
GtkFileFilter *all_filter = NULL;
GtkFileFilter *img_filter;
GtkFileFilter *all_filter;

dialog = gtk_file_chooser_dialog_new (_("Open Image"),
GTK_WINDOW(window),
Expand Down Expand Up @@ -1345,10 +1345,9 @@ vnr_window_cmd_open(GtkAction *action, VnrWindow *window)
g_signal_connect(GTK_FILE_CHOOSER(dialog), "update-preview",
G_CALLBACK(update_preview_cb), preview);

gchar *dirname;
if(window->file_list != NULL)
{
dirname = g_path_get_dirname (VNR_FILE(window->file_list->data)->path);
gchar *dirname = g_path_get_dirname (VNR_FILE(window->file_list->data)->path);
gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER(dialog), dirname);
g_free(dirname);
}
Expand Down Expand Up @@ -1377,10 +1376,9 @@ vnr_window_cmd_open_dir(GtkAction *action, VnrWindow *window)
gtk_window_set_modal (GTK_WINDOW(dialog), FALSE);
gtk_file_chooser_set_select_multiple(GTK_FILE_CHOOSER(dialog), TRUE);

gchar *dirname;
if(window->file_list != NULL)
{
dirname = g_path_get_dirname (VNR_FILE(window->file_list->data)->path);
gchar *dirname = g_path_get_dirname (VNR_FILE(window->file_list->data)->path);
gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER(dialog), dirname);
g_free(dirname);
}
Expand Down Expand Up @@ -1581,11 +1579,11 @@ vnr_window_cmd_scrollbar (GtkAction *action, VnrWindow *window)
static void
vnr_window_cmd_slideshow (GtkAction *action, VnrWindow *window)
{
g_assert(window != NULL && VNR_IS_WINDOW(window));

if(!window->slideshow)
return;

g_assert(window != NULL && VNR_IS_WINDOW(window));

gboolean slideshow;

slideshow = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));
Expand Down

0 comments on commit 9160eaa

Please sign in to comment.