Skip to content

Instantly share code, notes, and snippets.

@Superlokkus
Created August 31, 2015 12:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Superlokkus/58bd750e5bd9a9f63bfa to your computer and use it in GitHub Desktop.
Save Superlokkus/58bd750e5bd9a9f63bfa to your computer and use it in GitHub Desktop.
ODB bi-directional weak_ptr session destructor access violation
> msvcr120d.dll!operator delete(void * pUserData) Line 52 C++
odb_playground.exe!std::allocator<wchar_t>::deallocate(wchar_t * _Ptr, unsigned int __formal) Line 573 C++
odb_playground.exe!std::_Wrap_alloc<std::allocator<wchar_t> >::deallocate(wchar_t * _Ptr, unsigned int _Count) Line 859 C++
odb_playground.exe!std::basic_string<wchar_t,std::char_traits<wchar_t>,std::allocator<wchar_t> >::_Tidy(bool _Built, unsigned int _Newsize) Line 2284 C++
odb_playground.exe!std::basic_string<wchar_t,std::char_traits<wchar_t>,std::allocator<wchar_t> >::~basic_string<wchar_t,std::char_traits<wchar_t>,std::allocator<wchar_t> >() Line 992 C++
odb_playground.exe!std::basic_string<wchar_t,std::char_traits<wchar_t>,std::allocator<wchar_t> >::`scalar deleting destructor'(unsigned int) C++
odb_playground.exe!boost::optional_detail::optional_base<std::basic_string<wchar_t,std::char_traits<wchar_t>,std::allocator<wchar_t> > >::destroy_impl(boost::mpl::bool_<0> __formal) Line 722 C++
odb_playground.exe!boost::optional_detail::optional_base<std::basic_string<wchar_t,std::char_traits<wchar_t>,std::allocator<wchar_t> > >::destroy() Line 685 C++
odb_playground.exe!boost::optional_detail::optional_base<std::basic_string<wchar_t,std::char_traits<wchar_t>,std::allocator<wchar_t> > >::~optional_base<std::basic_string<wchar_t,std::char_traits<wchar_t>,std::allocator<wchar_t> > >() Line 327 C++
odb_playground.exe!boost::optional<std::basic_string<wchar_t,std::char_traits<wchar_t>,std::allocator<wchar_t> > >::~optional<std::basic_string<wchar_t,std::char_traits<wchar_t>,std::allocator<wchar_t> > >() Line 854 C++
[External Code]
odb-d-2.4-vc12.dll!odb::details::bits::counter_ops<odb::details::shared_base,odb::session::object_map_base>::dec(odb::session::object_map_base * p) Line 166 C++
odb-d-2.4-vc12.dll!odb::details::shared_ptr<odb::session::object_map_base>::~shared_ptr<odb::session::object_map_base>() Line 28 C++
[External Code]
odb-d-2.4-vc12.dll!odb::session::~session() Line 35 C++
odb_playground.exe!main(int argc, char * * argv) Line 72 C++
[External Code]
/*! @file directory.h
To be compiled first with the odb compiler
Copyright Markus Klemm markus@markusklemm.net
im Auftrag für RHe Microsystems GmbH
*/
#ifndef DIRECTORY_H
#define DIRECTORY_H
#include <string>
#include <ctime>
#include <memory>
#include <boost/date_time/posix_time/posix_time_types.hpp>
#include <boost/uuid/uuid.hpp>
#include <odb/core.hxx>
#include <boost/optional.hpp>
#include "file.h"
namespace MDDB_Service {
namespace MDDB_Web{
class file;
#pragma db object table("directories") session pointer(std::shared_ptr<directory>)
class directory
{
public:
#pragma db column("directory_id") type("uniqueidentifier") id not_null
boost::uuids::uuid directory_id;
#pragma db column("full_path") type("nvarchar(512)") not_null
std::wstring full_path;
#pragma db column("file_type") type("bigint") not_null
int64_t file_type;
#pragma db column("active") type("bit") not_null
bool active;
#pragma db column("added") type("datetime2") not_null
boost::posix_time::ptime added;
#pragma db column("added_by") type("varchar(32)") not_null
std::string added_by;
directory() : active(true)
{}
#pragma db inverse(directory)
std::vector<std::shared_ptr<file>> files;
};
}
}
#endif
/*! @file file.h
To be compiled first with the odb compiler
Copyright Markus Klemm markus@markusklemm.net
im Auftrag für RHe Microsystems GmbH
*/
#ifndef FILE_H
#define FILE_H
#include <string>
#include <ctime>
#include <memory>
#include <boost/date_time/posix_time/posix_time_types.hpp>
#include <boost/uuid/uuid.hpp>
#include <odb/core.hxx>
#include <boost/optional.hpp>
#include "directory.h"
namespace MDDB_Service {
namespace MDDB_Web{
class directory;
#pragma db object table("files") bulk(5000) session
class file
{
public:
#pragma db column("file_id") type("uniqueidentifier") id not_null
boost::uuids::uuid file_id;
#pragma db column("file_name") type("nvarchar(256)") not_null
std::wstring file_name;
#pragma db column("directory_id") not_null
std::weak_ptr<directory> directory;
#pragma db column("fully_uploaded") type("bit") not_null
bool fully_uploaded;
#pragma db column("partially_uploaded") type("bit") not_null
bool partially_uploaded;
#pragma db column("read_time") type("datetime2") not_null
boost::posix_time::ptime read_time;
#pragma db column("uploader_log") type("nvarchar(max)") null
boost::optional<std::wstring> uploader_log;
file() : fully_uploaded(false), partially_uploaded(false) {}
};
}
}
#endif
// odb_playground.cpp : Defines the entry point for the console application.
//
#include <iostream>
#include <memory>
#include <thread>
#include <string>
#include <locale>
#include <codecvt>
#include <boost/date_time/posix_time/posix_time.hpp>
#include <boost/date_time/gregorian/gregorian.hpp>
#include <boost/uuid/uuid_io.hpp>
#include <odb/core.hxx>
#include <odb/database.hxx>
#include <odb/mssql/database.hxx>
#include <odb/mssql/connection-factory.hxx>
#include <odb/mssql/exceptions.hxx>
#include "directory-odb.hxx"
#include "file-odb.hxx"
int main(int argc, char* argv[])
{
try{
std::auto_ptr<odb::mssql::connection_pool_factory> connection_factory(
new odb::mssql::connection_pool_factory(0, std::thread::hardware_concurrency()));
std::unique_ptr<odb::database> db(
new odb::mssql::database("dsn=mddb_local_32", odb::mssql::isolation_read_committed, static_cast<SQLHENV>(0), connection_factory)
);
{
odb::session s;
odb::transaction t(db->begin());
odb::result<MDDB_Service::MDDB_Web::directory> result(
db->query <MDDB_Service::MDDB_Web::directory>());
auto it = result.begin();
while (true)
{
static int i = 0;
if (i++ > 10 || it == result.end())
break;
std::wcout << "directory_id " << it->directory_id << " full_path "
<< it->full_path << " added: ";
std::cout << boost::posix_time::to_iso_string(it->added) << "\n";
++i;
}
t.rollback();
s.reset_current();//Not needed but for demonstration
}
{
odb::session s;
odb::transaction t(db->begin());
odb::result<MDDB_Service::MDDB_Web::file> result(
db->query <MDDB_Service::MDDB_Web::file>());
auto it = result.begin();
while (true)
{
static int i = 0;
if (i++ > 10 || it == result.end())
break;
std::wcout << "file_id " << it->file_id << " file_name "
<< it->file_name << "dir: " << std::shared_ptr<MDDB_Service::MDDB_Web::directory>(it->directory)->full_path << " read_time: ";
std::cout << boost::posix_time::to_iso_string(it->read_time) << "\n";
++i;
}
t.rollback();
s.reset_current(); //Throws in next line with this call and without
}// throws in ~session e.g. delete (looks like double delete) with
/*Unhandled exception at 0x0092A9E8 (msvcr120d.dll) in odb_playground.exe: 0xC0000005: Access violation reading location 0xFEEEFEE2.*/
std::cout << "block end" << std::endl;
}
catch (const odb::database_exception &e) {
std::cout << "ODB database error: " << e.what() << std::endl;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment