Skip to Content.
Sympa Menu

freetds - Re: [freetds] Segfault with latest stable FreeTDS release...

freetds AT lists.ibiblio.org

Subject: FreeTDS Development Group

List archive

Chronological Thread  
  • From: Frediano Ziglio <freddyz77 AT tin.it>
  • To: FreeTDS Development Group <freetds AT lists.ibiblio.org>
  • Subject: Re: [freetds] Segfault with latest stable FreeTDS release...
  • Date: Wed, 31 Mar 2004 21:03:42 +0200

Il mar, 2004-03-30 alle 12:50, James Vanns ha scritto:
> Hi all,
>
> This has been frustrating me somewhat; I am using FreeTDS in a C++
> application. I have a LOGIN struct etc encapsulated within a class. I
> can then use this class fine when it's allocated on the stack of a
> function e.g.:
>
> class tds {
> private:
> TDS_LOGIN l;
> TDS_SOCKET s;
> etc...
> };
>
> void function (void) {
> tds t;
> t.connect ("server", "username");
> t.do_query ("whatever");
> }
>
> and everything works fine. I get results and can print them out etc.
> However if I allocate t on the heap as in:
>
> tds *t = new tds;
>
> and try and connect to the database FreeTDS segfaults here:
>
> <snip>
> Program received signal SIGSEGV, Segmentation fault.
> _______________________________________________________________________________
> eax:00000004 ebx:40064D9C ecx:00000000 edx:08085788
> eflags:00210202
> esi:08081538 edi:BFFFE370 esp:BFFFE240 ebp:BFFFE268
> eip:40047B39
> cs:0023 ds:002B es:002B fs:0000 gs:0033 ss:002B o d I t s z
> a p c
> [002B:BFFFE240]---------------------------------------------------------[stack]
> BFFFE270 : 38 15 08 08 70 E3 FF BF - 98 E2 FF BF 11 7B 03 40
> 8...p........{.@
> BFFFE260 : 38 15 08 08 70 E3 FF BF - 98 E2 FF BF C3 6A 04 40
> 8...p........j.@
> BFFFE250 : 38 15 08 08 70 E3 FF BF - FB 7A 04 40 9C 4D 06 40
> 8...p....z.@.M.@
> BFFFE240 : 48 15 08 08 78 E4 04 08 - 20 59 08 08 9C 4D 06 40 H...x...
> Y...M.@
> [002B:08081538]---------------------------------------------------------[
> data]
> 08081538 : D0 15 08 08 99 05 00 00 - 08 00 00 00 00 02 00 00
> ................
> 08081548 : 88 57 08 08 7A 49 06 40 - 0A 00 00 00 98 57 08 08
> .W..zI.@.....W..
> [0023:40047B39]---------------------------------------------------------[
> code]
> 0x40047b39 <tds_config_login+73>: cmpb $0x0,(%eax)
> 0x40047b3c <tds_config_login+76>: jne 0x40047cf0
> <tds_config_login+512>
> 0x40047b42 <tds_config_login+82>: mov 0x5c(%edi),%eax
> 0x40047b45 <tds_config_login+85>: cmpb $0x0,(%eax)
> 0x40047b48 <tds_config_login+88>: jne 0x40047ca7
> <tds_config_login+439>
> 0x40047b4e <tds_config_login+94>: mov 0x1c(%edi),%eax
> ------------------------------------------------------------------------------
> 0x40047b39 in tds_config_login (connect_info=0x8081538,
> login=0xbfffe370) at config.c:469
> 469 if (!tds_dstr_isempty(&login->server_charset)) {
> gdb> bt
> #0 0x40047b39 in tds_config_login (connect_info=0x8081538,
> login=0xbfffe370) at config.c:469
> #1 0x40046ac3 in tds_read_config_info (tds=0x0, login=0xbfffe370,
> locale=0x4) at config.c:160
> #2 0x4006aeb7 in tds::login::connect() () from /usr/lib/libtdsxx.so.0
> </snip>
>
> Why!!!???? I can't figure out why it should decided to segv at this
> point only when it's on the heap. I can see that is something to do with
> server_charset - I can't set this via a tds function so what is it used
> for? What is it's initial value etc.
>
> Can anyone shed any light on this for me please!!??
>

I think that FreeTDS free your structure freeing your class so later on
accessing freed memory cause this problem.
You should allocate FreeTDS structures using FreeTDS API.
Another reason can be that you didn't initialize TDSLOGIN structure
properly. Usually structures are initialized in FreeTDS just after
allocation (see tds_alloc_login in src/tds/mem.c).
Also as James suggest remember that libTDS is subject to change without
notice. We don't care about binary compatibility of libTDS !!

freddy77






Archive powered by MHonArc 2.6.24.

Top of Page