Package: newsbeuter / 2.9-8

05-fix-memory-leak.patch Patch series | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
Description: Fix memory leak
 Fix severe memory leak when updating the feeds.
Origin: upstream, https://github.com/akrennmair/newsbeuter/pull/213
Bug: https://github.com/akrennmair/newsbeuter/issues/119
Bug-Debian: https://bugs.debian.org/776728

--- a/include/rss.h
+++ b/include/rss.h
@@ -117,7 +117,7 @@
 
 		void set_feedptr(std::shared_ptr<rss_feed> ptr);
 		inline std::shared_ptr<rss_feed> get_feedptr() {
-			return feedptr;
+			return feedptr_.lock();
 		}
 
 		inline bool deleted() const {
@@ -167,7 +167,7 @@
 		bool enqueued_;
 		std::string flags_;
 		std::string oldflags_;
-		std::shared_ptr<rss_feed> feedptr;
+		std::weak_ptr<rss_feed> feedptr_;
 		bool deleted_;
 		unsigned int idx;
 		std::string base;
--- a/src/rss.cpp
+++ b/src/rss.cpp
@@ -27,7 +27,6 @@
 }
 
 rss_item::~rss_item() {
-	feedptr.reset();
 	// LOG(LOG_CRITICAL, "delete rss_item");
 }
 
@@ -91,6 +90,7 @@
 
 void rss_item::set_unread_nowrite_notify(bool u, bool notify) {
 	unread_ = u;
+	std::shared_ptr<rss_feed> feedptr = feedptr_.lock();
 	if (feedptr && notify) {
 		feedptr->get_item_by_guid(guid_)->set_unread_nowrite(unread_); // notify parent feed
 	}
@@ -100,6 +100,7 @@
 	if (unread_ != u) {
 		bool old_u = unread_;
 		unread_ = u;
+		std::shared_ptr<rss_feed> feedptr = feedptr_.lock();
 		if (feedptr)
 			feedptr->get_item_by_guid(guid_)->set_unread_nowrite(unread_); // notify parent feed
 		try {
@@ -243,6 +244,7 @@
 		return true;
 
 	// if we have a feed, then forward the request
+	std::shared_ptr<rss_feed> feedptr = feedptr_.lock();
 	if (feedptr)
 		return feedptr->rss_feed::has_attribute(attribname);
 
@@ -276,6 +278,7 @@
 		return utils::to_string<unsigned int>(idx);
 
 	// if we have a feed, then forward the request
+	std::shared_ptr<rss_feed> feedptr = feedptr_.lock();
 	if (feedptr)
 		return feedptr->rss_feed::get_attribute(attribname);
 
@@ -563,7 +566,7 @@
 }
 
 void rss_item::set_feedptr(std::shared_ptr<rss_feed> ptr) {
-	feedptr = ptr;
+	feedptr_ = std::weak_ptr<rss_feed>(ptr);
 }
 
 std::string rss_feed::get_status() {