Skip to content

clean up valgrind error#685

Merged
rakshasa merged 1 commit intorakshasa:masterfrom
slingamn:valgrind_cleanup
Apr 21, 2026
Merged

clean up valgrind error#685
rakshasa merged 1 commit intorakshasa:masterfrom
slingamn:valgrind_cleanup

Conversation

@slingamn
Copy link
Copy Markdown
Contributor

This ensures that the new[] call here:

m_data.reset(new mapped_type[ls * num_layers]);

is paired with a delete[] call instead of a delete call, fixing this class of Valgrind errors:

==1324887== Mismatched new/delete size value: 4
==1324887==    at 0x484A5B9: operator delete(void*, unsigned long) (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
==1324887==    by 0x49C0307: operator() (unique_ptr.h:99)
==1324887==    by 0x49C0307: ~unique_ptr (unique_ptr.h:404)
==1324887==    by 0x49C0307: ~PartialQueue (partial_queue.h:28)
==1324887==    by 0x49C0307: ~ChunkSelector (chunk_selector.h:24)
==1324887==    by 0x49C0307: torrent::DownloadMain::~DownloadMain() (download_main.cc:88)
==1324887==    by 0x49C4210: operator() (unique_ptr.h:99)
==1324887==    by 0x49C4210: operator() (unique_ptr.h:93)
==1324887==    by 0x49C4210: ~unique_ptr (unique_ptr.h:404)
==1324887==    by 0x49C4210: torrent::DownloadWrapper::~DownloadWrapper() (download_wrapper.cc:63)
==1324887==    by 0x495233C: torrent::DownloadManager::erase(torrent::DownloadWrapper*) (download_manager.cc:62)
==1324887==    by 0x166950: core::DownloadList::erase(std::_List_iterator<core::Download*>) (download_list.cc:211)
==1324887==    by 0x1691B7: erase_ptr (download_list.cc:190)
==1324887==    by 0x1691B7: core::DownloadList::process_meta_download(core::Download*) (download_list.cc:709)
==1324887==    by 0x4985005: operator() (std_function.h:591)
==1324887==    by 0x4985005: torrent::utils::Scheduler::perform(std::chrono::duration<long, std::ratio<1l, 1000000l> >) (scheduler.cc:171)
==1324887==    by 0x4987C37: torrent::utils::Thread::event_loop() (thread.cc:188)
==1324887==    by 0x15B825: main (main.cc:441)
==1324887==  Address 0x6460160 is 0 bytes inside a block of size 1,024 alloc'd
==1324887==    at 0x48485C3: operator new[](unsigned long) (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
==1324887==    by 0x49B7533: enable (partial_queue.h:82)
==1324887==    by 0x49B7533: torrent::ChunkSelector::initialize(torrent::ChunkStatistics*) (chunk_selector.cc:28)
==1324887==    by 0x49C47A5: torrent::DownloadWrapper::receive_initial_hash() (download_wrapper.cc:140)
==1324887==    by 0x4985005: operator() (std_function.h:591)
==1324887==    by 0x4985005: torrent::utils::Scheduler::perform(std::chrono::duration<long, std::ratio<1l, 1000000l> >) (scheduler.cc:171)
==1324887==    by 0x4987C37: torrent::utils::Thread::event_loop() (thread.cc:188)
==1324887==    by 0x15B825: main (main.cc:441)

There should be no functional change. On the plus side, with this patch, I no longer see any errors in valgrind, including the DHT errors from #166.

@rakshasa rakshasa merged commit 628614b into rakshasa:master Apr 21, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants