removed file-leak code, temporarily used to trouble-shoot files appearing to be left open
This commit is contained in:
parent
1cf3689578
commit
1d1ab4f4b5
3
Jamfile
3
Jamfile
|
@ -379,9 +379,6 @@ feature.compose <sanitize>address : <cflags>-fsanitize=address <linkflags>-fsani
|
||||||
# RTC (runtime check) is an msvc feature
|
# RTC (runtime check) is an msvc feature
|
||||||
feature.compose <sanitize>rtc : <cflags>/RTCc <cflags>/RTCsu ;
|
feature.compose <sanitize>rtc : <cflags>/RTCc <cflags>/RTCsu ;
|
||||||
|
|
||||||
feature file-leak-logging : off on : composite propagated ;
|
|
||||||
feature.compose <file-leak-logging>on : <define>TORRENT_DEBUG_FILE_LEAKS=1 ;
|
|
||||||
|
|
||||||
feature i2p : on off : composite propagated ;
|
feature i2p : on off : composite propagated ;
|
||||||
feature.compose <i2p>on : <define>TORRENT_USE_I2P=1 ;
|
feature.compose <i2p>on : <define>TORRENT_USE_I2P=1 ;
|
||||||
feature.compose <i2p>off : <define>TORRENT_USE_I2P=0 ;
|
feature.compose <i2p>off : <define>TORRENT_USE_I2P=0 ;
|
||||||
|
|
|
@ -207,31 +207,7 @@ namespace libtorrent
|
||||||
|
|
||||||
struct file;
|
struct file;
|
||||||
|
|
||||||
#ifdef TORRENT_DEBUG_FILE_LEAKS
|
|
||||||
struct file_handle
|
|
||||||
{
|
|
||||||
file_handle();
|
|
||||||
explicit file_handle(file* f);
|
|
||||||
file_handle(file_handle const& fh);
|
|
||||||
~file_handle();
|
|
||||||
file* operator->();
|
|
||||||
file const* operator->() const;
|
|
||||||
file& operator*();
|
|
||||||
file const& operator*() const;
|
|
||||||
file* get();
|
|
||||||
file const* get() const;
|
|
||||||
explicit operator bool() const;
|
|
||||||
file_handle& reset(file* f = nullptr);
|
|
||||||
|
|
||||||
char stack[2048];
|
|
||||||
private:
|
|
||||||
std::shared_ptr<file> m_file;
|
|
||||||
};
|
|
||||||
|
|
||||||
void TORRENT_EXTRA_EXPORT print_open_files(char const* event, char const* name);
|
|
||||||
#else
|
|
||||||
using file_handle = std::shared_ptr<file>;
|
using file_handle = std::shared_ptr<file>;
|
||||||
#endif
|
|
||||||
|
|
||||||
struct TORRENT_EXTRA_EXPORT file: boost::noncopyable
|
struct TORRENT_EXTRA_EXPORT file: boost::noncopyable
|
||||||
{
|
{
|
||||||
|
@ -333,10 +309,6 @@ namespace libtorrent
|
||||||
std::uint32_t file_id() const { return m_file_id; }
|
std::uint32_t file_id() const { return m_file_id; }
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef TORRENT_DEBUG_FILE_LEAKS
|
|
||||||
void print_info(FILE* out) const;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
handle_type m_file_handle;
|
handle_type m_file_handle;
|
||||||
|
@ -348,10 +320,6 @@ namespace libtorrent
|
||||||
#if defined TORRENT_WINDOWS
|
#if defined TORRENT_WINDOWS
|
||||||
static bool has_manage_volume_privs;
|
static bool has_manage_volume_privs;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef TORRENT_DEBUG_FILE_LEAKS
|
|
||||||
std::string m_file_path;
|
|
||||||
#endif
|
|
||||||
};
|
};
|
||||||
|
|
||||||
TORRENT_EXTRA_EXPORT int bufs_size(span<file::iovec_t const> bufs);
|
TORRENT_EXTRA_EXPORT int bufs_size(span<file::iovec_t const> bufs);
|
||||||
|
|
86
src/file.cpp
86
src/file.cpp
|
@ -73,11 +73,6 @@ POSSIBILITY OF SUCH DAMAGE.
|
||||||
#include "libtorrent/aux_/max_path.hpp" // for TORRENT_MAX_PATH
|
#include "libtorrent/aux_/max_path.hpp" // for TORRENT_MAX_PATH
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
|
||||||
#ifdef TORRENT_DEBUG_FILE_LEAKS
|
|
||||||
#include <set>
|
|
||||||
#include <cstdio>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// for convert_to_wstring and convert_to_native
|
// for convert_to_wstring and convert_to_native
|
||||||
#include "libtorrent/aux_/escape_string.hpp"
|
#include "libtorrent/aux_/escape_string.hpp"
|
||||||
#include "libtorrent/assert.hpp"
|
#include "libtorrent/assert.hpp"
|
||||||
|
@ -1361,10 +1356,6 @@ namespace libtorrent
|
||||||
{
|
{
|
||||||
close();
|
close();
|
||||||
|
|
||||||
#ifdef TORRENT_DEBUG_FILE_LEAKS
|
|
||||||
m_file_path = path;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef TORRENT_DISK_STATS
|
#ifdef TORRENT_DISK_STATS
|
||||||
m_file_id = silly_hash(path);
|
m_file_id = silly_hash(path);
|
||||||
#endif
|
#endif
|
||||||
|
@ -1543,14 +1534,6 @@ namespace libtorrent
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef TORRENT_DEBUG_FILE_LEAKS
|
|
||||||
void file::print_info(FILE* out) const
|
|
||||||
{
|
|
||||||
if (!is_open()) return;
|
|
||||||
std::fprintf(out, "\n===> FILE: %s\n", m_file_path.c_str());
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
bool file::is_open() const
|
bool file::is_open() const
|
||||||
{
|
{
|
||||||
return m_file_handle != INVALID_HANDLE_VALUE;
|
return m_file_handle != INVALID_HANDLE_VALUE;
|
||||||
|
@ -2221,73 +2204,4 @@ typedef struct _FILE_ALLOCATED_RANGE_BUFFER {
|
||||||
return start;
|
return start;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef TORRENT_DEBUG_FILE_LEAKS
|
|
||||||
std::set<file_handle*> global_file_handles;
|
|
||||||
std::mutex file_handle_mutex;
|
|
||||||
|
|
||||||
file_handle::file_handle()
|
|
||||||
{
|
|
||||||
std::lock_guard<std::mutex> l(file_handle_mutex);
|
|
||||||
global_file_handles.insert(this);
|
|
||||||
stack[0] = 0;
|
|
||||||
}
|
|
||||||
file_handle::file_handle(file* f): m_file(f)
|
|
||||||
{
|
|
||||||
std::lock_guard<std::mutex> l(file_handle_mutex);
|
|
||||||
global_file_handles.insert(this);
|
|
||||||
if (f) print_backtrace(stack, sizeof(stack), 10);
|
|
||||||
else stack[0] = 0;
|
|
||||||
}
|
|
||||||
file_handle::file_handle(file_handle const& fh)
|
|
||||||
{
|
|
||||||
std::lock_guard<std::mutex> l(file_handle_mutex);
|
|
||||||
global_file_handles.insert(this);
|
|
||||||
m_file = fh.m_file;
|
|
||||||
if (m_file) print_backtrace(stack, sizeof(stack), 10);
|
|
||||||
else stack[0] = 0;
|
|
||||||
}
|
|
||||||
file_handle::~file_handle()
|
|
||||||
{
|
|
||||||
std::lock_guard<std::mutex> l(file_handle_mutex);
|
|
||||||
global_file_handles.erase(this);
|
|
||||||
stack[0] = 0;
|
|
||||||
}
|
|
||||||
file* file_handle::operator->() { return m_file.get(); }
|
|
||||||
file const* file_handle::operator->() const { return m_file.get(); }
|
|
||||||
file& file_handle::operator*() { return *m_file.get(); }
|
|
||||||
file const& file_handle::operator*() const { return *m_file.get(); }
|
|
||||||
file* file_handle::get() { return m_file.get(); }
|
|
||||||
file const* file_handle::get() const { return m_file.get(); }
|
|
||||||
file_handle::operator bool() const { return m_file.get(); }
|
|
||||||
file_handle& file_handle::reset(file* f)
|
|
||||||
{
|
|
||||||
std::lock_guard<std::mutex> l(file_handle_mutex);
|
|
||||||
if (f) print_backtrace(stack, sizeof(stack), 10);
|
|
||||||
else stack[0] = 0;
|
|
||||||
l.unlock();
|
|
||||||
m_file.reset(f);
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
void print_open_files(char const* event, char const* name)
|
|
||||||
{
|
|
||||||
FILE* out = std::fopen("open_files.log", "a+");
|
|
||||||
std::lock_guard<std::mutex> l(file_handle_mutex);
|
|
||||||
std::fprintf(out, "\n\nEVENT: %s TORRENT: %s\n\n", event, name);
|
|
||||||
for (std::set<file_handle*>::iterator i = global_file_handles.begin()
|
|
||||||
, end(global_file_handles.end()); i != end; ++i)
|
|
||||||
{
|
|
||||||
TORRENT_ASSERT(*i != nullptr);
|
|
||||||
if (!*i) continue;
|
|
||||||
file_handle const& h = **i;
|
|
||||||
if (!h) continue;
|
|
||||||
|
|
||||||
if (!h->is_open()) continue;
|
|
||||||
h->print_info(out);
|
|
||||||
std::fprintf(out, "\n%s\n\n", h.stack);
|
|
||||||
}
|
|
||||||
std::fclose(out);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -587,10 +587,6 @@ namespace libtorrent
|
||||||
|
|
||||||
// close files that were opened in write mode
|
// close files that were opened in write mode
|
||||||
m_pool.release(storage_index());
|
m_pool.release(storage_index());
|
||||||
|
|
||||||
#if defined TORRENT_DEBUG_FILE_LEAKS
|
|
||||||
print_open_files("release files", m_files.name().c_str());
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool default_storage::has_any_file(storage_error& ec)
|
bool default_storage::has_any_file(storage_error& ec)
|
||||||
|
@ -651,10 +647,6 @@ namespace libtorrent
|
||||||
// valid.
|
// valid.
|
||||||
if (exists(old_name, ec.ec))
|
if (exists(old_name, ec.ec))
|
||||||
{
|
{
|
||||||
#if defined TORRENT_DEBUG_FILE_LEAKS
|
|
||||||
print_open_files("release files", m_files.name().c_str());
|
|
||||||
#endif
|
|
||||||
|
|
||||||
std::string new_path;
|
std::string new_path;
|
||||||
if (is_complete(new_filename)) new_path = new_filename;
|
if (is_complete(new_filename)) new_path = new_filename;
|
||||||
else new_path = combine_path(m_save_path, new_filename);
|
else new_path = combine_path(m_save_path, new_filename);
|
||||||
|
@ -712,10 +704,6 @@ namespace libtorrent
|
||||||
|
|
||||||
// make sure we don't have the files open
|
// make sure we don't have the files open
|
||||||
m_pool.release(storage_index());
|
m_pool.release(storage_index());
|
||||||
|
|
||||||
#if defined TORRENT_DEBUG_FILE_LEAKS
|
|
||||||
print_open_files("release files", m_files.name().c_str());
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void default_storage::delete_one_file(std::string const& p, error_code& ec)
|
void default_storage::delete_one_file(std::string const& p, error_code& ec)
|
||||||
|
@ -741,9 +729,6 @@ namespace libtorrent
|
||||||
// case
|
// case
|
||||||
if (!m_pool.assert_idle_files(storage_index()))
|
if (!m_pool.assert_idle_files(storage_index()))
|
||||||
{
|
{
|
||||||
#if defined TORRENT_DEBUG_FILE_LEAKS
|
|
||||||
print_open_files("delete-files idle assert failed", m_files.name().c_str());
|
|
||||||
#endif
|
|
||||||
TORRENT_ASSERT_FAIL();
|
TORRENT_ASSERT_FAIL();
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -756,10 +741,6 @@ namespace libtorrent
|
||||||
// delete it
|
// delete it
|
||||||
if (m_part_file) m_part_file.reset();
|
if (m_part_file) m_part_file.reset();
|
||||||
|
|
||||||
#if defined TORRENT_DEBUG_FILE_LEAKS
|
|
||||||
print_open_files("release files", m_files.name().c_str());
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (options == session::delete_files)
|
if (options == session::delete_files)
|
||||||
{
|
{
|
||||||
#if TORRENT_USE_ASSERTS
|
#if TORRENT_USE_ASSERTS
|
||||||
|
@ -823,10 +804,6 @@ namespace libtorrent
|
||||||
|
|
||||||
DFLOG(stderr, "[%p] delete_files result: %s\n", static_cast<void*>(this)
|
DFLOG(stderr, "[%p] delete_files result: %s\n", static_cast<void*>(this)
|
||||||
, ec.ec.message().c_str());
|
, ec.ec.message().c_str());
|
||||||
|
|
||||||
#if defined TORRENT_DEBUG_FILE_LEAKS
|
|
||||||
print_open_files("delete-files done", m_files.name().c_str());
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool default_storage::verify_resume_data(add_torrent_params const& rd
|
bool default_storage::verify_resume_data(add_torrent_params const& rd
|
||||||
|
@ -994,10 +971,6 @@ namespace libtorrent
|
||||||
|
|
||||||
m_pool.release(storage_index());
|
m_pool.release(storage_index());
|
||||||
|
|
||||||
#if defined TORRENT_DEBUG_FILE_LEAKS
|
|
||||||
print_open_files("release files", m_files.name().c_str());
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// indices of all files we ended up copying. These need to be deleted
|
// indices of all files we ended up copying. These need to be deleted
|
||||||
// later
|
// later
|
||||||
aux::vector<bool, file_index_t> copied_files(f.num_files(), false);
|
aux::vector<bool, file_index_t> copied_files(f.num_files(), false);
|
||||||
|
|
Loading…
Reference in New Issue