| 1 | From e11b656bda59ca31b4f9ab4c5a14696813b0f6f4 Mon Sep 17 00:00:00 2001 |
| 2 | From: Tilman Keskinoz <arved@FreeBSD.org> |
| 3 | Date: Thu, 12 Mar 2015 11:03:50 +0100 |
| 4 | Subject: [PATCH 1/3] Detach thread, to avoid thread being destructed when it |
| 5 | is going out of scope |
| 6 | |
| 7 | --- |
| 8 | src/pb_controller.cpp | 1 + |
| 9 | 1 file changed, 1 insertion(+) |
| 10 | |
| 11 | diff --git a/src/pb_controller.cpp b/src/pb_controller.cpp |
| 12 | index 09b5e89..da8ffcb 100644 |
| 13 | --- a/src/pb_controller.cpp |
| 14 | +++ b/src/pb_controller.cpp |
| 15 | @@ -287,6 +287,7 @@ void pb_controller::start_downloads() { |
| 16 | if (it->status() == DL_QUEUED) { |
| 17 | std::thread t {poddlthread(&(*it), cfg)}; |
| 18 | --dl2start; |
| 19 | + t.detach(); |
| 20 | } |
| 21 | } |
| 22 | } |
| 23 | |
| 24 | From f79e5527ba5f54677540637f5b8d287215cfa051 Mon Sep 17 00:00:00 2001 |
| 25 | From: Tilman Keskinoz <arved@FreeBSD.org> |
| 26 | Date: Thu, 12 Mar 2015 11:04:49 +0100 |
| 27 | Subject: [PATCH 2/3] Fix segfault |
| 28 | |
| 29 | I think somewhere the poddlthread is copied and the memory messed up. |
| 30 | Make it a shared_ptr to fix segfault. |
| 31 | |
| 32 | Why is this a pointer anyway? |
| 33 | --- |
| 34 | include/poddlthread.h | 3 ++- |
| 35 | src/poddlthread.cpp | 1 - |
| 36 | 2 files changed, 2 insertions(+), 2 deletions(-) |
| 37 | |
| 38 | diff --git a/include/poddlthread.h b/include/poddlthread.h |
| 39 | index a10b9e7..cf0f1da 100644 |
| 40 | --- a/include/poddlthread.h |
| 41 | +++ b/include/poddlthread.h |
| 42 | @@ -7,6 +7,7 @@ |
| 43 | |
| 44 | #include <sys/time.h> |
| 45 | #include <time.h> |
| 46 | +#include <memory> |
| 47 | |
| 48 | #include <configcontainer.h> |
| 49 | |
| 50 | @@ -24,7 +25,7 @@ class poddlthread { |
| 51 | private: |
| 52 | void mkdir_p(const char * file); |
| 53 | download * dl; |
| 54 | - std::ofstream *f; |
| 55 | + std::shared_ptr<std::ofstream> f; |
| 56 | timeval tv1; |
| 57 | timeval tv2; |
| 58 | size_t bytecount; |
| 59 | diff --git a/src/poddlthread.cpp b/src/poddlthread.cpp |
| 60 | index 583481e..3a1b390 100644 |
| 61 | --- a/src/poddlthread.cpp |
| 62 | +++ b/src/poddlthread.cpp |
| 63 | @@ -22,7 +22,6 @@ poddlthread::poddlthread(download * dl_, newsbeuter::configcontainer * c) : dl(d |
| 64 | } |
| 65 | |
| 66 | poddlthread::~poddlthread() { |
| 67 | - delete f; |
| 68 | } |
| 69 | |
| 70 | void poddlthread::operator()() { |
| 71 | |
| 72 | From 49dbf84d9500860c48c1d3137cf0d7ab89588726 Mon Sep 17 00:00:00 2001 |
| 73 | From: Tilman Keskinoz <arved@FreeBSD.org> |
| 74 | Date: Thu, 12 Mar 2015 11:30:24 +0100 |
| 75 | Subject: [PATCH 3/3] Another threa.detach() missing |
| 76 | |
| 77 | --- |
| 78 | src/pb_view.cpp | 1 + |
| 79 | 1 file changed, 1 insertion(+) |
| 80 | |
| 81 | diff --git a/src/pb_view.cpp b/src/pb_view.cpp |
| 82 | index fb61c72..f3cb478 100644 |
| 83 | --- a/src/pb_view.cpp |
| 84 | +++ b/src/pb_view.cpp |
| 85 | @@ -111,6 +111,7 @@ void pb_view::run(bool auto_download) { |
| 86 | if (idx != -1) { |
| 87 | if (ctrl->downloads()[idx].status() != DL_DOWNLOADING) { |
| 88 | std::thread t {poddlthread(&ctrl->downloads()[idx], ctrl->get_cfgcont())}; |
| 89 | + t.detach(); |
| 90 | } |
| 91 | } |
| 92 | } |