SOCI / soci

Official repository of the SOCI - The C++ Database Access Library
http://soci.sourceforge.net/
Boost Software License 1.0
1.37k stars 472 forks source link

vcpkg soci crashes on session::close() #1114

Closed ISBachvarov21 closed 6 months ago

ISBachvarov21 commented 6 months ago
#pragma once

//#include <soci/soci.h>
//#include <soci/postgresql/soci-postgresql.h>
#include "soci/soci.h"
#include "soci/postgresql/soci-postgresql.h"
#include <iostream>
#include <istream>
#include <ostream>
#include <string>
#include <exception>
#include <functional>

using namespace soci;
using namespace std;

int main()
{
    try
    {
        session sql(postgresql, "<conn string here>");
        if (sql.is_connected()) {
            cout << "Connected successfully\n";
        }
        else {
            cout << "Not connected\n";
        }

        sql.close();

        //int count;
        //sql << "select count(*) from users", into(count);

        //cout << "We have " << count << " entries in users.\n";
    }
    catch (exception const& e)
    {
        cerr << "Error: " << e.what() << '\n';
    }
    catch (soci_error const& e)
    {
        cerr << "Error: " << e.what() << '\n';
    }

}

this code snippet generates an access violation reading location from soci-test.exe (libcrypto-3-x64.dll) when sql.close() is called or the session object enters its destructor (connection string has been hidden for obvious reasons)

#pragma once

//#include <soci/soci.h>
//#include <soci/postgresql/soci-postgresql.h>
#include "soci/soci.h"
#include "soci/postgresql/soci-postgresql.h"
#include <iostream>
#include <istream>
#include <ostream>
#include <string>
#include <exception>
#include <functional>

using namespace soci;
using namespace std;

int main()
{
    try
    {
        session* sql = new session(postgresql, "<conn string here>");
        if (sql->is_connected()) {
            cout << "Connected successfully\n";
        }
        else {
            cout << "Not connected\n";
        }

        sql = nullptr;

        //int count;
        //sql << "select count(*) from users", into(count);

        //cout << "We have " << count << " entries in users.\n";
    }
    catch (exception const& e)
    {
        cerr << "Error: " << e.what() << '\n';
    }
    catch (soci_error const& e)
    {
        cerr << "Error: " << e.what() << '\n';
    }

}

what i found is that initializing sql as a session* through the constructor of session and then later on instead of sql.close() doing sql = nullptr doesn't throw, with the only catch being that this is obviously a memory leak (delete sql before sql = nullptr throws the same error)

NOTE: doing free(sql) works like a charm, so i suppose i'll be using that for now

vadz commented 6 months ago

Looks like a build options mismatch, I'm pretty sure that if you build SOCI yourself your problem would go away.

And I'm sorry, but problems like this are almost impossible to diagnose remotely, you need to ensure that you use the same compiler options for your code as were used for the package and there is nothing we can do about it, so it's not useful to keep this open.