newsbeuter-2.9-fix-mem-leak.patch 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. From cdacfbde9fe3ae2489fc96d35dfb7d263ab03f50 Mon Sep 17 00:00:00 2001
  2. From: cpubug <admin@crtx.ru>
  3. Date: Sun, 8 Nov 2015 13:15:25 +0300
  4. Subject: [PATCH] fixed a memory leak
  5. ---
  6. include/rss.h | 4 ++--
  7. src/rss.cpp | 7 +++++--
  8. 2 files changed, 7 insertions(+), 4 deletions(-)
  9. diff --git a/include/rss.h b/include/rss.h
  10. index bc0ef03..f8c87f2 100644
  11. --- a/include/rss.h
  12. +++ b/include/rss.h
  13. @@ -117,7 +117,7 @@ class rss_item : public matchable {
  14. void set_feedptr(std::shared_ptr<rss_feed> ptr);
  15. inline std::shared_ptr<rss_feed> get_feedptr() {
  16. - return feedptr;
  17. + return feedptr_.lock();
  18. }
  19. inline bool deleted() const {
  20. @@ -167,7 +167,7 @@ class rss_item : public matchable {
  21. bool enqueued_;
  22. std::string flags_;
  23. std::string oldflags_;
  24. - std::shared_ptr<rss_feed> feedptr;
  25. + std::weak_ptr<rss_feed> feedptr_;
  26. bool deleted_;
  27. unsigned int idx;
  28. std::string base;
  29. diff --git a/src/rss.cpp b/src/rss.cpp
  30. index 1687cbe..9cf0cce 100644
  31. --- a/src/rss.cpp
  32. +++ b/src/rss.cpp
  33. @@ -27,7 +27,6 @@ rss_item::rss_item(cache * c) : pubDate_(0), unread_(true), ch(c), enqueued_(fal
  34. }
  35. rss_item::~rss_item() {
  36. - feedptr.reset();
  37. // LOG(LOG_CRITICAL, "delete rss_item");
  38. }
  39. @@ -91,6 +90,7 @@ void rss_item::set_unread_nowrite(bool u) {
  40. void rss_item::set_unread_nowrite_notify(bool u, bool notify) {
  41. unread_ = u;
  42. + std::shared_ptr<rss_feed> feedptr = feedptr_.lock();
  43. if (feedptr && notify) {
  44. feedptr->get_item_by_guid(guid_)->set_unread_nowrite(unread_); // notify parent feed
  45. }
  46. @@ -100,6 +100,7 @@ void rss_item::set_unread(bool u) {
  47. if (unread_ != u) {
  48. bool old_u = unread_;
  49. unread_ = u;
  50. + std::shared_ptr<rss_feed> feedptr = feedptr_.lock();
  51. if (feedptr)
  52. feedptr->get_item_by_guid(guid_)->set_unread_nowrite(unread_); // notify parent feed
  53. try {
  54. @@ -243,6 +244,7 @@ bool rss_item::has_attribute(const std::string& attribname) {
  55. return true;
  56. // if we have a feed, then forward the request
  57. + std::shared_ptr<rss_feed> feedptr = feedptr_.lock();
  58. if (feedptr)
  59. return feedptr->rss_feed::has_attribute(attribname);
  60. @@ -276,6 +278,7 @@ std::string rss_item::get_attribute(const std::string& attribname) {
  61. return utils::to_string<unsigned int>(idx);
  62. // if we have a feed, then forward the request
  63. + std::shared_ptr<rss_feed> feedptr = feedptr_.lock();
  64. if (feedptr)
  65. return feedptr->rss_feed::get_attribute(attribname);
  66. @@ -563,7 +566,7 @@ void rss_feed::set_feedptrs(std::shared_ptr<rss_feed> self) {
  67. }
  68. void rss_item::set_feedptr(std::shared_ptr<rss_feed> ptr) {
  69. - feedptr = ptr;
  70. + feedptr_ = std::weak_ptr<rss_feed>(ptr);
  71. }
  72. std::string rss_feed::get_status() {
  73. --
  74. 2.9.3