OBConversion::Write() segfault

Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

OBConversion::Write() segfault

Steffen Neumann
Hi,

we're currently using the OB in the PostgreSQL chemistry
contrib module http://pgfoundry.org/projects/pgchem
and we seem to hit a problem somewhere, see logs below.

The code that is misbehaving is at the interface between OB and postgres,
and the actual segfault is in the destructor of the OBConversion() result,
but I am unsure whether the caller or the callee causes the problem,
so this mail's subject might be a bit misleading.
OB version is 2.2.3, compiled on g++-4.4.3 (Ubuntu 10.04)

Unfortunately it is not a specific molecule that breaks,
but the failure seems to be sporadic, some kind of memory corruption.
I was able to obtain a stacktrace via gdb -- see the end of the mail -- but I have no clue
what this translates to. Some comments on things I figured are inlined in the stacktrace.
The offending code is also at the end of the mail.

There, OBConversion is used to convert SetInAndOutFormats ("SMI", "MDL");
and the SEGV occurs in the destructor of the ostringstream molstream object,
which was the target of the conversion. Specifically it is the destructor
~basic_ostringstream, during its destruction it wants to release its ~basic_stringbuf
and the ~basic_string therein, which seems to be the ultimate failure
(I am not proficient in stack traces, is that something free'd twice,
or free'ing something that wasn't alloced before ? And there is
another ~basic_string further up the stack trace ?!)

My suspicion was that some dark pointer magic inside OBConversion
causes the problem. what is the best practise in OB
for hunting memory problems ? I get many issues through valgrind,
again I am unable to pinpoint which might be the root cause.
Maybe some experienced C++ hacker can deduce something
from the stacktrace.

Thanks for any pointers in advance,

Yours,
Steffen

(gdb) where
#0  0x00007f3ece7cb15e in ?? () from /lib/libc.so.6
#1  0x00007f3ece7543ac in ?? () from /lib/libc.so.6
#2  0x00007f3ece752e48 in free () from /lib/libc.so.6
#3  0x00007f3ec9d6f129 in std::string::_Rep::_M_dispose (this=<value optimized out>, __in_chrg=<value optimized out>)
    at /build/buildd/gcc-4.4-4.4.3/build/x86_64-linux-gnu/libstdc++-v3/include/bits/basic_string.h:231
#4  ~basic_string (this=<value optimized out>, __in_chrg=<value optimized out>)
    at /build/buildd/gcc-4.4-4.4.3/build/x86_64-linux-gnu/libstdc++-v3/include/bits/basic_string.h:498
#5  0x00007f3ece70e262 in exit () from /lib/libc.so.6
#6  0x00007f3ed07d2765 in quickdie ()
#7  <signal handler called>
#8  0x00007f3ece7b304a in brk () from /lib/libc.so.6
#9  0x00007f3ece7b30fd in sbrk () from /lib/libc.so.6
#10 0x00007f3ece7545f9 in __default_morecore () from /lib/libc.so.6
#11 0x00007f3ece74f694 in ?? () from /lib/libc.so.6
#12 0x00007f3ece752e53 in free () from /lib/libc.so.6
# Destructor cascade of ostringstream molstream
#13 0x00007f3ec9d6b363 in std::string::_Rep::_M_dispose (this=0x7fff02c16a20, __in_chrg=<value optimized out>, __vtt_parm=<value optimized out>)
    at /build/buildd/gcc-4.4-4.4.3/build/x86_64-linux-gnu/libstdc++-v3/include/bits/basic_string.h:231
#14 ~basic_string (this=0x7fff02c16a20, __in_chrg=<value optimized out>, __vtt_parm=<value optimized out>)
    at /build/buildd/gcc-4.4-4.4.3/build/x86_64-linux-gnu/libstdc++-v3/include/bits/basic_string.h:498
#15 ~basic_stringbuf (this=0x7fff02c16a20, __in_chrg=<value optimized out>, __vtt_parm=<value optimized out>)
    at /build/buildd/gcc-4.4-4.4.3/build/x86_64-linux-gnu/libstdc++-v3/include/iosfwd:63
#16 ~basic_ostringstream (this=0x7fff02c16a20, __in_chrg=<value optimized out>, __vtt_parm=<value optimized out>)
    at /build/buildd/gcc-4.4-4.4.3/build/x86_64-linux-gnu/libstdc++-v3/include/sstream:432
# From here on the postgres-OpenBabel glue stuff
#17 0x00007f3ecaa8f5c9 in ob_smiles_to_mol () from /usr/lib/postgresql/9.0/lib/libpgchem.so
#18 0x00007f3ecaa87ee0 in make_molecule (
    raw_input=0x7f3ed35a8c0c "CS(=O)(=O)C1=C(C=CC2=CC=CC=C21)NN=C3C(=CC4=CC(=CC(=C4C3=O)NC5=NC(=NC(=N5)NC6=C(C=C(C=C6)S(=O)(=O)O)C(=O)O)Cl)S(=O)(=O)O)S(=O)(=O)O)(=O)[O-]N(C)C2O/c1-6-10(2,3)9(13)11-7-8-1`)\326\322>\177", size=<value optimized out>) at molecule/molecule_io.c:483
#19 0x00007f3ed071c618 in ?? ()
# From here on Postgres stuff
#20 0x00007f3ed07179ee in ExecProject ()
#21 0x00007f3ed072d50b in ExecResult ()
#22 0x00007f3ed0716fd8 in ExecProcNode ()
#23 0x00007f3ed072bd6d in ExecModifyTable ()
#24 0x00007f3ed0716fc8 in ExecProcNode ()
#25 0x00007f3ed0715c82 in standard_ExecutorRun ()
#26 0x00007f3ed07d6e07 in ?? ()
#27 0x00007f3ed07d7038 in ?? ()
#28 0x00007f3ed07d78e2 in PortalRun ()
#29 0x00007f3ed07d4f6c in PostgresMain ()
#30 0x00007f3ed07a005a in ?? ()
#31 0x00007f3ed07a29f1 in PostmasterMain ()
#32 0x00007f3ed0747923 in main ()

############################################################################
#
# At the end of this function the destructur experiences the SEGV


extern "C" char *
ob_smiles_to_mol (char *smiles)
{
  OBMol mol;
  OBConversion conv;
  string tmpStr (smiles);
  string outstring;
  istringstream smilesstream (tmpStr);
  ostringstream molstream;
  char *tmpMolfile;

  conv.SetInAndOutFormats ("SMI", "MDL");

  conv.Read (&mol, &smilesstream);

  if (mol.Empty ())
    return NULL;

  conv.Write (&mol, &molstream);

  outstring = molstream.str ();
 
  // remove the trailling $$$$\n from the SDFile
  if (outstring.find ("$$$$\n", 0) != string::npos)
    {
      outstring = outstring.substr (0, outstring.length () - 5);
    }
  else if (outstring.find ("$$$$\r\n", 0) != string::npos)
    {
      outstring = outstring.substr (0, outstring.length () - 6);
    }

  tmpMolfile = strdup (outstring.c_str ());
  assert(tmpFile != NULL);

  return (tmpMolfile);
}

--
IPB Halle                    AG Massenspektrometrie & Bioinformatik
Dr. Steffen Neumann          http://www.IPB-Halle.DE
Weinberg 3                   http://msbi.bic-gh.de
06120 Halle                  Tel. +49 (0) 345 5582 - 1470
                                  +49 (0) 345 5582 - 0
sneumann(at)IPB-Halle.DE     Fax. +49 (0) 345 5582 - 1409



------------------------------------------------------------------------------
Start uncovering the many advantages of virtual appliances
and start using them to simplify application deployment and
accelerate your shift to cloud computing.
http://p.sf.net/sfu/novell-sfdev2dev
_______________________________________________
OpenBabel-discuss mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/openbabel-discuss
Reply | Threaded
Open this post in threaded view
|

Re: OBConversion::Write() segfault

Chris Morley-3
There are some outstanding issues with the auxiliary streams in
OBConversion and this may be a symptom. On the openbabel-Devel list
Gert Thijs, and others, have identified problems with
OBConversion::Read(OBBase* pOb, std::istream* pin=NULL)
He recommends that just the form like Read(&mol) should be used and
the input stream set separately. The same might be done with Write().

Possibly this could help to avoid your crash.

Chris

On 28/09/2010 14:57, Steffen Neumann wrote:

> Hi,
>
> we're currently using the OB in the PostgreSQL chemistry
> contrib module http://pgfoundry.org/projects/pgchem
> and we seem to hit a problem somewhere, see logs below.
>
> The code that is misbehaving is at the interface between OB and postgres,
> and the actual segfault is in the destructor of the OBConversion() result,
> but I am unsure whether the caller or the callee causes the problem,
> so this mail's subject might be a bit misleading.
> OB version is 2.2.3, compiled on g++-4.4.3 (Ubuntu 10.04)
>
> Unfortunately it is not a specific molecule that breaks,
> but the failure seems to be sporadic, some kind of memory corruption.
> I was able to obtain a stacktrace via gdb -- see the end of the mail -- but I have no clue
> what this translates to. Some comments on things I figured are inlined in the stacktrace.
> The offending code is also at the end of the mail.
>
> There, OBConversion is used to convert SetInAndOutFormats ("SMI", "MDL");
> and the SEGV occurs in the destructor of the ostringstream molstream object,
> which was the target of the conversion. Specifically it is the destructor
> ~basic_ostringstream, during its destruction it wants to release its ~basic_stringbuf
> and the ~basic_string therein, which seems to be the ultimate failure
> (I am not proficient in stack traces, is that something free'd twice,
> or free'ing something that wasn't alloced before ? And there is
> another ~basic_string further up the stack trace ?!)
>
> My suspicion was that some dark pointer magic inside OBConversion
> causes the problem. what is the best practise in OB
> for hunting memory problems ? I get many issues through valgrind,
> again I am unable to pinpoint which might be the root cause.
> Maybe some experienced C++ hacker can deduce something
> from the stacktrace.
>
> Thanks for any pointers in advance,
>
> Yours,
> Steffen
>
> (gdb) where
> #0  0x00007f3ece7cb15e in ?? () from /lib/libc.so.6
> #1  0x00007f3ece7543ac in ?? () from /lib/libc.so.6
> #2  0x00007f3ece752e48 in free () from /lib/libc.so.6
> #3  0x00007f3ec9d6f129 in std::string::_Rep::_M_dispose (this=<value optimized out>, __in_chrg=<value optimized out>)
>      at /build/buildd/gcc-4.4-4.4.3/build/x86_64-linux-gnu/libstdc++-v3/include/bits/basic_string.h:231
> #4  ~basic_string (this=<value optimized out>, __in_chrg=<value optimized out>)
>      at /build/buildd/gcc-4.4-4.4.3/build/x86_64-linux-gnu/libstdc++-v3/include/bits/basic_string.h:498
> #5  0x00007f3ece70e262 in exit () from /lib/libc.so.6
> #6  0x00007f3ed07d2765 in quickdie ()
> #7<signal handler called>
> #8  0x00007f3ece7b304a in brk () from /lib/libc.so.6
> #9  0x00007f3ece7b30fd in sbrk () from /lib/libc.so.6
> #10 0x00007f3ece7545f9 in __default_morecore () from /lib/libc.so.6
> #11 0x00007f3ece74f694 in ?? () from /lib/libc.so.6
> #12 0x00007f3ece752e53 in free () from /lib/libc.so.6
> # Destructor cascade of ostringstream molstream
> #13 0x00007f3ec9d6b363 in std::string::_Rep::_M_dispose (this=0x7fff02c16a20, __in_chrg=<value optimized out>, __vtt_parm=<value optimized out>)
>      at /build/buildd/gcc-4.4-4.4.3/build/x86_64-linux-gnu/libstdc++-v3/include/bits/basic_string.h:231
> #14 ~basic_string (this=0x7fff02c16a20, __in_chrg=<value optimized out>, __vtt_parm=<value optimized out>)
>      at /build/buildd/gcc-4.4-4.4.3/build/x86_64-linux-gnu/libstdc++-v3/include/bits/basic_string.h:498
> #15 ~basic_stringbuf (this=0x7fff02c16a20, __in_chrg=<value optimized out>, __vtt_parm=<value optimized out>)
>      at /build/buildd/gcc-4.4-4.4.3/build/x86_64-linux-gnu/libstdc++-v3/include/iosfwd:63
> #16 ~basic_ostringstream (this=0x7fff02c16a20, __in_chrg=<value optimized out>, __vtt_parm=<value optimized out>)
>      at /build/buildd/gcc-4.4-4.4.3/build/x86_64-linux-gnu/libstdc++-v3/include/sstream:432
> # From here on the postgres-OpenBabel glue stuff
> #17 0x00007f3ecaa8f5c9 in ob_smiles_to_mol () from /usr/lib/postgresql/9.0/lib/libpgchem.so
> #18 0x00007f3ecaa87ee0 in make_molecule (
>      raw_input=0x7f3ed35a8c0c "CS(=O)(=O)C1=C(C=CC2=CC=CC=C21)NN=C3C(=CC4=CC(=CC(=C4C3=O)NC5=NC(=NC(=N5)NC6=C(C=C(C=C6)S(=O)(=O)O)C(=O)O)Cl)S(=O)(=O)O)S(=O)(=O)O)(=O)[O-]N(C)C2O/c1-6-10(2,3)9(13)11-7-8-1`)\326\322>\177", size=<value optimized out>) at molecule/molecule_io.c:483
> #19 0x00007f3ed071c618 in ?? ()
> # From here on Postgres stuff
> #20 0x00007f3ed07179ee in ExecProject ()
> #21 0x00007f3ed072d50b in ExecResult ()
> #22 0x00007f3ed0716fd8 in ExecProcNode ()
> #23 0x00007f3ed072bd6d in ExecModifyTable ()
> #24 0x00007f3ed0716fc8 in ExecProcNode ()
> #25 0x00007f3ed0715c82 in standard_ExecutorRun ()
> #26 0x00007f3ed07d6e07 in ?? ()
> #27 0x00007f3ed07d7038 in ?? ()
> #28 0x00007f3ed07d78e2 in PortalRun ()
> #29 0x00007f3ed07d4f6c in PostgresMain ()
> #30 0x00007f3ed07a005a in ?? ()
> #31 0x00007f3ed07a29f1 in PostmasterMain ()
> #32 0x00007f3ed0747923 in main ()
>
> ############################################################################
> #
> # At the end of this function the destructur experiences the SEGV
>
>
> extern "C" char *
> ob_smiles_to_mol (char *smiles)
> {
>    OBMol mol;
>    OBConversion conv;
>    string tmpStr (smiles);
>    string outstring;
>    istringstream smilesstream (tmpStr);
>    ostringstream molstream;
>    char *tmpMolfile;
>
>    conv.SetInAndOutFormats ("SMI", "MDL");
>
>    conv.Read (&mol,&smilesstream);
>
>    if (mol.Empty ())
>      return NULL;
>
>    conv.Write (&mol,&molstream);
>
>    outstring = molstream.str ();
>
>    // remove the trailling $$$$\n from the SDFile
>    if (outstring.find ("$$$$\n", 0) != string::npos)
>      {
>        outstring = outstring.substr (0, outstring.length () - 5);
>      }
>    else if (outstring.find ("$$$$\r\n", 0) != string::npos)
>      {
>        outstring = outstring.substr (0, outstring.length () - 6);
>      }
>
>    tmpMolfile = strdup (outstring.c_str ());
>    assert(tmpFile != NULL);
>
>    return (tmpMolfile);
> }
>
>
>
>
>
> No virus found in this incoming message.
> Checked by AVG - www.avg.com
> Version: 9.0.856 / Virus Database: 271.1.1/3163 - Release Date: 09/27/10 18:56:00
>


------------------------------------------------------------------------------
Start uncovering the many advantages of virtual appliances
and start using them to simplify application deployment and
accelerate your shift to cloud computing.
http://p.sf.net/sfu/novell-sfdev2dev
_______________________________________________
OpenBabel-discuss mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/openbabel-discuss
Reply | Threaded
Open this post in threaded view
|

Re: OBConversion::Write() segfault

arianapham
In reply to this post by Steffen Neumann
 I really like visiting your site because I think your posts are amazing. Thanks a lot for sharing them goomy clicker react
Reply | Threaded
Open this post in threaded view
|

Re: OBConversion::Write() segfault

havenhaven
In reply to this post by Chris Morley-3
The difference between the successful and the loser is not in strength, knowledge or understanding - but in will  happy wheels    super smash flash 2