From: Marco Pesenti Gritti Date: Tue, 31 May 2005 18:19:29 +0000 (+0000) Subject: Cleanup dispose a bit. Dont leak the whole pixmap. X-Git-Tag: EVINCE_0_3_3~302 X-Git-Url: https://www.fi.muni.cz/~kas/git//home/kas/public_html/git/?a=commitdiff_plain;h=b42e272da0aa35667ef56420347d3abe504bd04c;p=evince.git Cleanup dispose a bit. Dont leak the whole pixmap. 2005-05-31 Marco Pesenti Gritti * ps/ps-document.c: (ps_document_dispose), (ps_document_class_init), (stop_interpreter), (document_load): Cleanup dispose a bit. Dont leak the whole pixmap. --- diff --git a/ChangeLog b/ChangeLog index a2f40285..a7269ba8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2005-05-31 Marco Pesenti Gritti + + * ps/ps-document.c: (ps_document_dispose), + (ps_document_class_init), (stop_interpreter), (document_load): + + Cleanup dispose a bit. Dont leak the whole pixmap. + 2005-05-31 Marco Pesenti Gritti * pdf/ev-poppler.cc: diff --git a/ps/ps-document.c b/ps/ps-document.c index a38fc6bf..53f2e101 100644 --- a/ps/ps-document.c +++ b/ps/ps-document.c @@ -89,7 +89,6 @@ static gboolean broken_pipe = FALSE; /* Forward declarations */ static void ps_document_init(PSDocument * gs); static void ps_document_class_init(PSDocumentClass * klass); -static void ps_document_finalize(GObject * object); static void send_ps(PSDocument * gs, long begin, unsigned int len, gboolean close); static void close_pipe(int p[2]); static void output(gpointer data, gint source, GdkInputCondition condition); @@ -146,6 +145,46 @@ ps_document_init (PSDocument *gs) pixbuf_mutex = g_mutex_new (); } +static void +ps_document_dispose (GObject *object) +{ + PSDocument *gs = PS_DOCUMENT (object); + + g_return_if_fail (gs != NULL); + + if (gs->gs_psfile) { + fclose (gs->gs_psfile); + gs->gs_psfile = NULL; + } + + if (gs->gs_filename) { + g_free (gs->gs_filename); + gs->gs_filename = NULL; + } + + if (gs->doc) { + psfree (gs->doc); + gs->doc = NULL; + } + + if (gs->gs_filename_unc) { + unlink(gs->gs_filename_unc); + g_free(gs->gs_filename_unc); + gs->gs_filename_unc = NULL; + } + + if (gs->bpixmap) { + gdk_drawable_unref (gs->bpixmap); + } + + if(gs->input_buffer) { + g_free(gs->input_buffer); + gs->input_buffer = NULL; + } + + stop_interpreter (gs); +} + static void ps_document_class_init(PSDocumentClass *klass) { @@ -155,7 +194,7 @@ ps_document_class_init(PSDocumentClass *klass) parent_class = g_type_class_peek_parent (klass); gs_class = klass; - object_class->finalize = ps_document_finalize; + object_class->dispose = ps_document_dispose; klass->gs_atom = gdk_atom_intern ("GHOSTVIEW", FALSE); klass->next_atom = gdk_atom_intern ("NEXT", FALSE); @@ -192,40 +231,6 @@ interpreter_failed (PSDocument *gs, char *msg) stop_interpreter (gs); } -static void -ps_document_cleanup (PSDocument *gs) -{ - g_return_if_fail (gs != NULL); - g_return_if_fail (PS_IS_DOCUMENT (gs)); - - LOG ("Cleanup\n"); - - stop_interpreter (gs); - - if (gs->gs_psfile) { - fclose (gs->gs_psfile); - gs->gs_psfile = NULL; - } - - if (gs->gs_filename) { - g_free (gs->gs_filename); - gs->gs_filename = NULL; - } - - if (gs->doc) { - psfree (gs->doc); - gs->doc = NULL; - } - - if (gs->gs_filename_unc) { - unlink(gs->gs_filename_unc); - g_free(gs->gs_filename_unc); - gs->gs_filename_unc = NULL; - } - - gs->loaded = FALSE; -} - static gboolean ps_document_widget_event (GtkWidget *widget, GdkEvent *event, gpointer data) { @@ -246,29 +251,6 @@ ps_document_widget_event (GtkWidget *widget, GdkEvent *event, gpointer data) return TRUE; } -static void -ps_document_finalize (GObject * object) -{ - PSDocument *gs; - - g_return_if_fail (object != NULL); - g_return_if_fail (PS_IS_DOCUMENT (object)); - - LOG ("Finalize"); - - gs = PS_DOCUMENT (object); - - ps_document_cleanup (gs); - stop_interpreter (gs); - - if(gs->input_buffer) { - g_free(gs->input_buffer); - gs->input_buffer = NULL; - } - - (*G_OBJECT_CLASS (parent_class)->finalize) (object); -} - static void send_ps(PSDocument * gs, long begin, unsigned int len, gboolean close) { @@ -821,7 +803,6 @@ stop_interpreter(PSDocument * gs) while((wait(&status) == -1) && (errno == EINTR)) ; gs->interpreter_pid = -1; if(status == 1) { - ps_document_cleanup(gs); gs->gs_status = _("Interpreter failed."); } } @@ -1026,9 +1007,6 @@ document_load(PSDocument * gs, const gchar * fname) LOG ("Load the document"); - /* clean up previous document */ - ps_document_cleanup(gs); - if(fname == NULL) { gs->gs_status = ""; return FALSE; @@ -1071,7 +1049,6 @@ document_load(PSDocument * gs, const gchar * fname) if(!filename || (gs->gs_psfile = fopen(filename, "r")) == NULL) { interpreter_failed (gs, NULL); - ps_document_cleanup(gs); return FALSE; } @@ -1083,7 +1060,6 @@ document_load(PSDocument * gs, const gchar * fname) gchar buf[1024]; g_snprintf(buf, 1024, _("Error while scanning file %s\n"), fname); interpreter_failed (gs, buf); - ps_document_cleanup(gs); gs->gs_status = _("The file is not a PostScript document."); return FALSE; }