Bug Summary

File:menu_blacklists.c
Location:line 90, column 1
Description:Potential memory leak

Annotated Source Code

1/* -*- c++ -*-
2Copyright (C) 2004-2013 Christian Wieninger
3
4This program is free software; you can redistribute it and/or
5modify it under the terms of the GNU General Public License
6as published by the Free Software Foundation; either version 2
7of the License, or (at your option) any later version.
8
9This program is distributed in the hope that it will be useful,
10but WITHOUT ANY WARRANTY; without even the implied warranty of
11MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12GNU General Public License for more details.
13
14You should have received a copy of the GNU General Public License
15along with this program; if not, write to the Free Software
16Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17Or, point your browser to http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
18
19The author can be reached at cwieninger@gmx.de
20
21The project's page is at http://winni.vdr-developer.org/epgsearch
22*/
23
24#include <vector>
25#include <string>
26#include <iomanip>
27#include <sstream>
28
29#include "menu_blacklists.h"
30#include "epgsearchtools.h"
31#include "menu_blacklistedit.h"
32#include "epgsearchcfg.h"
33#include "menu_searchresults.h"
34
35using namespace std;
36
37// --- cMenuBlacklistsItem ----------------------------------------------------------
38class cMenuBlacklistsItem : public cOsdItem {
39 private:
40public:
41 cBlacklist* blacklist;
42 cMenuBlacklistsItem(cBlacklist* Blacklist);
43 int Compare(const cListObject &ListObject) const;
44 void Set(void);
45 };
46
47cMenuBlacklistsItem::cMenuBlacklistsItem(cBlacklist* Blacklist)
48{
49 blacklist = Blacklist;
50 Set();
1
Calling 'cMenuBlacklistsItem::Set'
51}
52
53void cMenuBlacklistsItem::Set(void)
54{
55 ostringstream line;
56
57 if (blacklist->isGlobal != 0)
2
Taking false branch
58 line << setiosflags(ios::left) << "G";
59 line << "\t";
60
61 if (blacklist->search && strlen(blacklist->search) > 0)
3
Taking false branch
62 line << setiosflags(ios::left) << string(blacklist->search);
63 else
64 line << setiosflags(ios::left) << "*";
65
66 line << "\t";
67 if (blacklist->useChannel == 1)
4
Taking false branch
68 {
69 if (blacklist->channelMin != blacklist->channelMax)
70 line << setiosflags(ios::left) << blacklist->channelMin->Number() << " - " << blacklist->channelMax->Number();
71 else
72 line << setiosflags(ios::left) << setw(11) << (blacklist->useChannel?CHANNELNAME(blacklist->channelMin)(blacklist->channelMin ? blacklist->channelMin->ShortName
(true) : "")
:"");
73 }
74 else if (blacklist->useChannel == 2)
5
Taking false branch
75 line << setiosflags(ios::left) << setw(11) << blacklist->channelGroup;
76
77 line << "\t";
78 if (blacklist->useTime)
6
Taking false branch
79 {
80 ostringstream timeline;
81 timeline << setfill('0') << setw(2) << blacklist->startTime / 100 << ":" << setw(2) << blacklist->startTime % 100;
82 timeline << "\t";
83 timeline << setfill('0') << setw(2) << blacklist->stopTime / 100 << ":" << setw(2) << blacklist->stopTime % 100;
84 line << timeline.str();
85 }
86 else
87 line << "--:--\t--:--";
88
89 SetText(strdup(line.str().c_str()), false);
7
Memory is allocated
90}
8
Potential memory leak
91
92int cMenuBlacklistsItem::Compare(const cListObject &ListObject) const
93{
94 cMenuBlacklistsItem *p = (cMenuBlacklistsItem *)&ListObject;
95 return strcasecmp(blacklist->search, p->blacklist->search);
96}
97
98// --- cMenuBlacklists ----------------------------------------------------------
99cMenuBlacklists::cMenuBlacklists()
100:cOsdMenu(tr("Blacklists")I18nTranslate("Blacklists", "vdr-" "epgsearch"), 3, 20, 11, 6, 5)
101{
102#if VDRVERSNUM20005 >= 10734
103 SetMenuCategory(mcSetupPlugins);
104#endif
105 cMutexLock BlacklistLock(&Blacklists);
106 cBlacklist *Blacklist = Blacklists.First();
107 while (Blacklist) {
108 Add(new cMenuBlacklistsItem(Blacklist));
109 Blacklist = Blacklists.Next(Blacklist);
110 }
111 SetHelp(trVDR("Button$Edit")I18nTranslate("Button$Edit"), trVDR("Button$New")I18nTranslate("Button$New"), trVDR("Button$Delete")I18nTranslate("Button$Delete"), NULL__null);
112 Sort();
113 Display();
114
115}
116
117cBlacklist *cMenuBlacklists::CurrentBlacklist(void)
118{
119 cMenuBlacklistsItem *item = (cMenuBlacklistsItem *)Get(Current());
120 if (item && Blacklists.Exists(item->blacklist))
121 return item->blacklist;
122 return NULL__null;
123}
124
125eOSState cMenuBlacklists::New(void)
126{
127 if (HasSubMenu())
128 return osContinue;
129 return AddSubMenu(new cMenuBlacklistEdit(new cBlacklist, true));
130}
131
132eOSState cMenuBlacklists::Delete(void)
133{
134 cBlacklist *curBlacklist = CurrentBlacklist();
135 if (curBlacklist) {
136 if (Interface->Confirm(tr("Edit$Delete blacklist?")I18nTranslate("Edit$Delete blacklist?", "vdr-" "epgsearch"))) {
137 LogFile.Log(1,"blacklist %s (%d) deleted", curBlacklist->search, curBlacklist->ID);
138 SearchExts.RemoveBlacklistID(curBlacklist->ID);
139 cMutexLock BlacklistLock(&Blacklists);
140 Blacklists.Del(curBlacklist);
141 Blacklists.Save();
142 cOsdMenu::Del(Current());
143 Display();
144 }
145 }
146 return osContinue;
147}
148
149eOSState cMenuBlacklists::ProcessKey(eKeys Key)
150{
151 int BlacklistNumber = HasSubMenu() ? Count() : -1;
152 eOSState state = cOsdMenu::ProcessKey(Key);
153 if (state == osUnknown) {
154 if (HasSubMenu())
155 return osContinue;
156 switch (Key) {
157 case kOk:
158 return AddSubMenu(new cMenuSearchResultsForBlacklist(CurrentBlacklist()));
159 break;
160 case kRed:
161 if (CurrentBlacklist())
162 state = AddSubMenu(new cMenuBlacklistEdit(CurrentBlacklist()));
163 else
164 state = osContinue;
165 break;
166 case kGreen: state = New(); break;
167 case kYellow: state = Delete(); break;
168 default: break;
169 }
170 }
171 if (BlacklistNumber >= 0 && !HasSubMenu())
172 {
173 cMutexLock BlacklistLock(&Blacklists);
174 cBlacklist* Blacklist = Blacklists.Get(BlacklistNumber);
175 if (Blacklist) // a newly created search was confirmed with Ok
176 Add(new cMenuBlacklistsItem(Blacklist));
177 // always update all entries, since channel group names may have changed and affect other searches
178 Sort();
179 for(int i=0; i<Count(); i++)
180 {
181 cMenuBlacklistsItem *item = (cMenuBlacklistsItem *)Get(i);
182 if (item)
183 {
184 item->Set();
185 if (item->blacklist == Blacklist)
186 SetCurrent(item);
187 }
188 }
189 Display();
190 }
191
192 return state;
193}