[fbreader] Fixed a few memory leaks

This commit is contained in:
Slava Monich 2018-05-06 00:57:34 +03:00
parent 24749c646a
commit c49d8af7a3
5 changed files with 27 additions and 9 deletions

View file

@ -422,6 +422,14 @@ XHTMLTagAction *XHTMLReader::addAction(const std::string &tag, XHTMLTagAction *a
return old;
}
void XHTMLReader::clearTagTable() {
ActionMap::iterator it = ourTagActions.begin();
while (it != ourTagActions.end()) {
delete it->second;
ourTagActions.erase(it++);
}
}
void XHTMLReader::fillTagTable() {
if (ourTagActions.empty()) {
//addAction("html", new XHTMLTagAction());
@ -480,7 +488,6 @@ void XHTMLReader::fillTagTable() {
addAction("br", new XHTMLTagLineBreakAction());
//addAction("center", new XHTMLTagAction());
addAction("div", new XHTMLTagParagraphAction());
addAction("dt", new XHTMLTagParagraphAction());
//addAction("head", new XHTMLTagAction());
//addAction("hr", new XHTMLTagAction());
addAction("link", new XHTMLTagLinkAction());

View file

@ -1,5 +1,6 @@
/*
* Copyright (C) 2004-2010 Geometer Plus <contact@geometerplus.com>
* Copyright (C) 2016-2018 Slava Monich <slava.monich@jolla.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -56,9 +57,11 @@ class XHTMLReader : public ZLXMLReader {
public:
static XHTMLTagAction *addAction(const std::string &tag, XHTMLTagAction *action);
static void fillTagTable();
static void clearTagTable();
private:
static std::map<std::string,XHTMLTagAction*> ourTagActions;
typedef std::map<std::string,XHTMLTagAction*> ActionMap;
static ActionMap ourTagActions;
public:
XHTMLReader(BookReader &modelReader);

View file

@ -1,5 +1,6 @@
/*
* Copyright (C) 2009-2010 Geometer Plus <contact@geometerplus.com>
* Copyright (C) 2016-2018 Slava Monich <slava.monich@jolla.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -137,3 +138,9 @@ void Tag::setTagId(shared_ptr<Tag> tag, int tagId) {
tag->myTagId = tagId;
ourTagsById[tagId] = tag;
}
void Tag::clearTags()
{
ourRootTags.clear();
ourTagsById.clear();
}

View file

@ -1,5 +1,6 @@
/*
* Copyright (C) 2009-2010 Geometer Plus <contact@geometerplus.com>
* Copyright (C) 2016-2018 Slava Monich <slava.monich@jolla.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -37,6 +38,7 @@ public:
static shared_ptr<Tag> getTag(const std::string &name, shared_ptr<Tag> parent = 0, int tagId = 0);
static shared_ptr<Tag> getTagByFullName(const std::string &fullName);
static shared_ptr<Tag> getTagById(int tagId);
static void clearTags();
static void setTagId(shared_ptr<Tag>, int tagId);

View file

@ -143,15 +143,14 @@ MyOneByteEncodingConverter::MyOneByteEncodingConverter(const std::string &encodi
myEncodingMap = new char[1024];
memset(myEncodingMap, '\0', 1024);
for (int i = 0; i < 256; ++i) {
ZLUnicodeUtil::ucs4ToUtf8(myEncodingMap + 4 * i, i);
}
if (encodingMap != 0) {
for (int i = 0; i < 256; ++i) {
if (encodingMap[i] != 0) {
strcpy(myEncodingMap + 4 * i, encodingMap[i]);
}
if (encodingMap[i]) {
strcpy(myEncodingMap + 4 * i, encodingMap[i]);
delete[] encodingMap[i];
} else {
ZLUnicodeUtil::ucs4ToUtf8(myEncodingMap + 4 * i, i);
}
}
delete[] encodingMap;
}
MyOneByteEncodingConverter::~MyOneByteEncodingConverter() {