From 51e36fa15805fdf64d68113ef66910f3f6c8eede Mon Sep 17 00:00:00 2001 From: Gehad elrobey Date: Fri, 10 Jul 2015 14:59:56 +0200 Subject: Printing: handle memory leak in printer class Don't initialize new webview each time we print. Delete the QWebView object in the destructor. Signed-off-by: Gehad elrobey Signed-off-by: Lubomir I. Ivanov --- printer.cpp | 7 ++++++- printer.h | 1 + 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/printer.cpp b/printer.cpp index f8a90f96d..446a5c29d 100644 --- a/printer.cpp +++ b/printer.cpp @@ -13,6 +13,12 @@ Printer::Printer(QPrinter *printer, print_options *printOptions, template_option this->templateOptions = templateOptions; dpi = 0; done = 0; + webView = new QWebView(); +} + +Printer::~Printer() +{ + delete webView; } void Printer::putProfileImage(QRect profilePlaceholder, QRect viewPort, QPainter *painter, struct dive *dive, QPointer profile) @@ -118,7 +124,6 @@ void Printer::templateProgessUpdated(int value) void Printer::print() { TemplateLayout t(printOptions, templateOptions); - webView = new QWebView(); connect(&t, SIGNAL(progressUpdated(int)), this, SLOT(templateProgessUpdated(int))); dpi = printer->resolution(); diff --git a/printer.h b/printer.h index 4ab65834a..73368a669 100644 --- a/printer.h +++ b/printer.h @@ -29,6 +29,7 @@ private slots: public: Printer(QPrinter *printer, print_options *printOptions, template_options *templateOptions); + ~Printer(); void print(); signals: -- cgit v1.2.3-70-g09d2