Merge pull request #5619

f2f207d miner: fix double free of thread attributes (ston1th)
This commit is contained in:
luigi1111 2019-06-11 18:17:11 -05:00
commit fd0cf689dd
No known key found for this signature in database
GPG Key ID: F4ACA0183641E010
4 changed files with 8 additions and 18 deletions

View File

@ -123,7 +123,7 @@ namespace cryptonote
m_miner_extra_sleep(BACKGROUND_MINING_DEFAULT_MINER_EXTRA_SLEEP_MILLIS), m_miner_extra_sleep(BACKGROUND_MINING_DEFAULT_MINER_EXTRA_SLEEP_MILLIS),
m_block_reward(0) m_block_reward(0)
{ {
m_attrs.set_stack_size(THREAD_STACK_SIZE);
} }
//----------------------------------------------------------------------------------------------------- //-----------------------------------------------------------------------------------------------------
miner::~miner() miner::~miner()
@ -360,7 +360,7 @@ namespace cryptonote
return m_threads_total; return m_threads_total;
} }
//----------------------------------------------------------------------------------------------------- //-----------------------------------------------------------------------------------------------------
bool miner::start(const account_public_address& adr, size_t threads_count, const boost::thread::attributes& attrs, bool do_background, bool ignore_battery) bool miner::start(const account_public_address& adr, size_t threads_count, bool do_background, bool ignore_battery)
{ {
m_block_reward = 0; m_block_reward = 0;
m_mine_address = adr; m_mine_address = adr;
@ -371,7 +371,6 @@ namespace cryptonote
m_threads_autodetect.push_back({epee::misc_utils::get_ns_count(), m_total_hashes}); m_threads_autodetect.push_back({epee::misc_utils::get_ns_count(), m_total_hashes});
m_threads_total = 1; m_threads_total = 1;
} }
m_attrs = attrs;
m_starter_nonce = crypto::rand<uint32_t>(); m_starter_nonce = crypto::rand<uint32_t>();
CRITICAL_REGION_LOCAL(m_threads_lock); CRITICAL_REGION_LOCAL(m_threads_lock);
if(is_mining()) if(is_mining())
@ -395,7 +394,7 @@ namespace cryptonote
for(size_t i = 0; i != m_threads_total; i++) for(size_t i = 0; i != m_threads_total; i++)
{ {
m_threads.push_back(boost::thread(attrs, boost::bind(&miner::worker_thread, this))); m_threads.push_back(boost::thread(m_attrs, boost::bind(&miner::worker_thread, this)));
} }
if (threads_count == 0) if (threads_count == 0)
@ -405,7 +404,7 @@ namespace cryptonote
if( get_is_background_mining_enabled() ) if( get_is_background_mining_enabled() )
{ {
m_background_mining_thread = boost::thread(attrs, boost::bind(&miner::background_worker_thread, this)); m_background_mining_thread = boost::thread(m_attrs, boost::bind(&miner::background_worker_thread, this));
LOG_PRINT_L0("Background mining controller thread started" ); LOG_PRINT_L0("Background mining controller thread started" );
} }
@ -487,10 +486,7 @@ namespace cryptonote
{ {
if(m_do_mining) if(m_do_mining)
{ {
boost::thread::attributes attrs; start(m_mine_address, m_threads_total, get_is_background_mining_enabled(), get_ignore_battery());
attrs.set_stack_size(THREAD_STACK_SIZE);
start(m_mine_address, m_threads_total, attrs, get_is_background_mining_enabled(), get_ignore_battery());
} }
} }
//----------------------------------------------------------------------------------------------------- //-----------------------------------------------------------------------------------------------------

View File

@ -64,7 +64,7 @@ namespace cryptonote
static void init_options(boost::program_options::options_description& desc); static void init_options(boost::program_options::options_description& desc);
bool set_block_template(const block& bl, const difficulty_type& diffic, uint64_t height, uint64_t block_reward); bool set_block_template(const block& bl, const difficulty_type& diffic, uint64_t height, uint64_t block_reward);
bool on_block_chain_update(); bool on_block_chain_update();
bool start(const account_public_address& adr, size_t threads_count, const boost::thread::attributes& attrs, bool do_background = false, bool ignore_battery = false); bool start(const account_public_address& adr, size_t threads_count, bool do_background = false, bool ignore_battery = false);
uint64_t get_speed() const; uint64_t get_speed() const;
uint32_t get_threads_count() const; uint32_t get_threads_count() const;
void send_stop_signal(); void send_stop_signal();

View File

@ -905,16 +905,13 @@ namespace cryptonote
return true; return true;
} }
boost::thread::attributes attrs;
attrs.set_stack_size(THREAD_STACK_SIZE);
cryptonote::miner &miner= m_core.get_miner(); cryptonote::miner &miner= m_core.get_miner();
if (miner.is_mining()) if (miner.is_mining())
{ {
res.status = "Already mining"; res.status = "Already mining";
return true; return true;
} }
if(!miner.start(info.address, static_cast<size_t>(req.threads_count), attrs, req.do_background_mining, req.ignore_battery)) if(!miner.start(info.address, static_cast<size_t>(req.threads_count), req.do_background_mining, req.ignore_battery))
{ {
res.status = "Failed, mining not started"; res.status = "Failed, mining not started";
LOG_PRINT_L0(res.status); LOG_PRINT_L0(res.status);

View File

@ -408,10 +408,7 @@ namespace rpc
return; return;
} }
boost::thread::attributes attrs; if(!m_core.get_miner().start(info.address, static_cast<size_t>(req.threads_count), req.do_background_mining, req.ignore_battery))
attrs.set_stack_size(THREAD_STACK_SIZE);
if(!m_core.get_miner().start(info.address, static_cast<size_t>(req.threads_count), attrs, req.do_background_mining, req.ignore_battery))
{ {
res.error_details = "Failed, mining not started"; res.error_details = "Failed, mining not started";
LOG_PRINT_L0(res.error_details); LOG_PRINT_L0(res.error_details);