Results 1 to 4 of 4

Thread: QSqlDatabase::open Segfaults

  1. #1
    Join Date
    Jun 2010
    Posts
    4
    Qt products
    Platforms
    MacOS X Unix/X11

    Default QSqlDatabase::open Segfaults

    I'm using Qt4 with Python 2.6.5 on Ubuntu (Lucid)

    I have a function that opens a DB connection using QSqlDatabase:pen, which is segfaulting in some instances. I have been unable to create a simple test case that reproduces it, but it happens every time I run the program, on the fifth time it is called. As far as I can tell, the call and everything about the QSqlDatabase instance are identical and I can't determine what makes it segfault.

    def Open( self ):
    # self._db is a QSqlDatabase instance
    if not self._db.isOpen():
    etl.Log( "Opening connection to %s" % ( self.Name ) )

    if etl.DebugMode:
    print "driverName: %s" % ( self._db.driverName() )
    print "hostName: %s" % ( self._db.hostName() )
    print "databaseName: %s" % ( self._db.databaseName() )
    print "userName: %s" % ( self._db.userName() )
    print "password: %s" % ( "*" * len(self._db.password()) )
    print "isDriverAvailable: %s" % ( self._db.isDriverAvailable( self._db.driverName() ) )
    print "isOpen: %s" % ( self._db.isOpen() )
    print "isOpenError: %s" % ( self._db.isOpenError() )
    print "isValid: %s" % ( self._db.isValid() )

    if not self._db.open():
    raise Exception( "Could not open connection to %s" % ( self.Name ) )


    The output of which is:
    Opening connection to ERP Rollup
    driverName: QTDS
    hostName: dev-nav01.skinit.loc
    databaseName: Demo Database NAV (6-0)
    userName: etl
    password: ********
    isDriverAvailable: True
    isOpen: False
    isOpenError: False
    isValid: True

    Program received signal SIGSEGV, Segmentation fault.
    0x00007ffff0a1d42b in dblib_add_connection (login=<value optimized out>,
    server=<value optimized out>, msdblib=<value optimized out>) at dblib.c:239
    239 dblib.c: No such file or directory.
    in dblib.c


    Using gdb, I find the local vars in dlib.c to be:
    i = 0
    list_size = 4096


    The last couple of lines from the FreeTDS log are:
    07:49:34.247604 6159 (token.c:495):tds_process_tokens(0x14e5270, 0x7fffffffd13c, 0x7fffffffd138, 0x100)
    07:49:34.247631 6159 (token.c:498):tds_process_tokens() state is COMPLETED
    07:49:34.247683 6159 (dblib.c:237):dblib_add_connection(0x7ffff0c695a0, 0x14e5270)


    So I also used gdb to check out the values at those memory addresses:
    0x7ffff0c695a0 <g_dblib_ctx>: 0x00000000
    0x14e5270: 0x00000007


    I'm not a C/C++ programmer, so I'm unsure how to proceed, but it looks like it's the NULL pointer causing the problem (though the 0x00000007 is suspicious as well, cause the dblib_add_connection args are both pointers and I wouldn't expect to find a pointer with that low of a memory address).


    I really would appreciate any help someone can provide. Also, if anyone can tell me if this is the type of incident that a commercial support license would cover, that might be an avenue I can go down.

  2. #2
    Join Date
    Jun 2010
    Posts
    4
    Qt products
    Platforms
    MacOS X Unix/X11

    Default Re: QSqlDatabase::open Segfaults

    Hmmm.... I think maybe I was reading the freetds log wrong. I thought the address needed to be dereferenced, but it looks now like those addresses are already dereferenced, so there is no NULL pointer, it instead looks like the pointer is pointing as a class instance in which the data begins with 0x00000000.

    I think that actually leaves me worse off since I have no idea what might be wrong now.

  3. #3
    Join Date
    Jun 2010
    Posts
    4
    Qt products
    Platforms
    MacOS X Unix/X11

    Default Re: QSqlDatabase::open Segfaults

    More info:
    (gdb) p g_dblib_ctx
    $1 = {ref_count = 0, tds_ctx = 0x109cbf0, tds_ctx_ref_count = 1,
    connection_list = 0x0, connection_list_size = 0,
    connection_list_size_represented = 4096, recftos_filename = 0x0,
    recftos_filenum = 0, login_timeout = -1, query_timeout = -1}


    It looks to me like maybe the ref_count is the problem. I can't imagine a ref_count of 0 being correct for a argument as it seems the caller must have a reference. Maybe I'm reading too much into that though.

  4. #4
    Join Date
    Jun 2010
    Posts
    4
    Qt products
    Platforms
    MacOS X Unix/X11

    Default Re: QSqlDatabase::open Segfaults

    It occurred to me a stack trace may be useful:

    #0 0x00007ffff0a1d42b in dblib_add_connection (login=<value optimized out>,
    server=<value optimized out>, msdblib=<value optimized out>) at dblib.c:239
    #1 tdsdbopen (login=<value optimized out>, server=<value optimized out>,
    msdblib=<value optimized out>) at dblib.c:1156
    #2 0x00007ffff0c72dfc in ?? ()
    from /usr/lib/qt4/plugins/sqldrivers/libqsqltds.so
    #3 0x00007ffff4544ad0 in QSqlDatabase:pen() () from /usr/lib/libQtSql.so.4
    #4 0x00007ffff47a2e4d in ?? ()
    from /usr/lib/pymodules/python2.6/PyQt4/QtSql.so
    #5 0x00000000004a7c5e in PyEval_EvalFrameEx ()
    #6 0x00000000004a8550 in PyEval_EvalFrameEx ()
    #7 0x00000000004a9671 in PyEval_EvalCodeEx ()
    #8 0x00000000004a7809 in PyEval_EvalFrameEx ()
    #9 0x00000000004a8550 in PyEval_EvalFrameEx ()
    #10 0x00000000004a8550 in PyEval_EvalFrameEx ()
    #11 0x00000000004a8550 in PyEval_EvalFrameEx ()
    #12 0x00000000004a9671 in PyEval_EvalCodeEx ()
    #13 0x00000000004a9742 in PyEval_EvalCode ()
    #14 0x00000000004c9a0e in PyRun_FileExFlags ()
    #15 0x00000000004c9c24 in PyRun_SimpleFileExFlags ()
    #16 0x000000000041a7ff in Py_Main ()
    #17 0x00007ffff69dac4d in __libc_start_main () from /lib/libc.so.6
    #18 0x00000000004199f9 in _start ()

Similar Threads

  1. QSqlDatabase::open() fails with QODBC
    By grzywacz in forum Qt Programming
    Replies: 4
    Last Post: 7th April 2010, 03:27
  2. Why QSqlDatabase::open() returns open?
    By gboelter in forum Newbie
    Replies: 7
    Last Post: 27th August 2009, 18:52
  3. Replies: 4
    Last Post: 16th August 2008, 02:42
  4. How to catch segfaults?
    By Daliphant in forum Newbie
    Replies: 4
    Last Post: 3rd July 2008, 14:17
  5. Anyone an idea why this code segfaults?
    By Kumosan in forum Qt Programming
    Replies: 4
    Last Post: 28th April 2007, 05:53

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.