(FYI, CC'd to soci-users)

On 31 May 2013 08:04, Mr. Last <[email protected]> wrote:
> Good day,
>
> first of all I want to say that SOCI is really brilliant. It does not happen
> often that I find a library that is well designed and works at it should.

On behalf of the team, thank you!

> However I had to face crashes when closing my database connection to
> PostgreSQL.
>
> If a soci::statement is used you have to call "statement::clean_up()" before
> closing the sessions.

Yes, it is correct for your use case.

> Otherwise the Application crashes when a thread or the
> main thread is terminated. I did not find any information about this in your
> documentation so i guess it is unknown? I would appriciate feedback, see
> attached source file.

In your program, you close session leaving statement with dangling
pointer to session object.
Next, statement's destructor is called and attempts to clean up itself
using the wild pointer to session what obviously leads to crash.

You have to ensure the following sequence of events:

1. open session
2. create statement
3. destroy statement
4. close session

Your program swaps step 3. and 4.

Now, you have choices to perform 3. and 4.
If you allocate session/statement on heap, then call clean_up() and
close() methods.
If you create those as automatic objects, then let the scoping ensure
proper sequence of events.

p.s. I'd suggest to post directly to soci-users or feel free to open issue at
https://github.com/SOCI/soci/issues/

Best regards,
-- 
Mateusz Loskot, http://mateusz.loskot.net

------------------------------------------------------------------------------
Get 100% visibility into Java/.NET code with AppDynamics Lite
It's a free troubleshooting tool designed for production
Get down to code-level detail for bottlenecks, with <2% overhead.
Download for free and get started troubleshooting in minutes.
http://p.sf.net/sfu/appdyn_d2d_ap2
_______________________________________________
soci-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/soci-users

Reply via email to