[freetds] help

Thomas Stover thomas at wsinnovations.com
Mon Jul 7 20:03:38 EDT 2008


OK everything was working fine. Then over the weekend something happened 
somewhere, and now I can't get a connection to our ms sql 2000 server 
even with a simple test program. I was using 0.63-3.2.ubuntu x86_64. 
(why was ubuntu so out of date?) So I removed that package, and built 
0.82 from source. I get a segfault trying to difference a NULL pointer. 
Here is my test program and valgrind output. Any ideas? I did look at 
that line in dblib.c, and it looks like you might need to check for 
NULL. Or is that the point - it should never be NULL?

Anyone else do a 'doz update or anything that broke their setup lately?

#include <stdio.h>
#include <sqlfront.h>
#include <sqldb.h>
#include <string.h>

#ifndef HAVE_WINDOWS_H
#define PDBPROCESS DBPROCESS *
#define PLOGINREC LOGINREC *
#endif

int err_handler(DBPROCESS *dbproc, int severity, int dberr,
                int oserr, char *dberrstr, char *oserrstr)
{
 fprintf(stderr, "DB-Library Error %i: %s\ns", dberr, dberrstr);
 if (oserr != DBNOERR)
  fprintf(stderr, "Operating System Error %i: %s\n", oserr, oserrstr);

 return INT_CANCEL;
}

int msg_handler(DBPROCESS *dbproc, DBINT msgno, int msgstate,
                int severity, char *msgtext, char *srvname, char *proc, 
int line)
{
 fprintf(stderr, "SQL Server Message %d: %s\n" , msgno, msgtext);

 return 0;
}


int main(void)
{
 unsigned char temp[512];
 PDBPROCESS dbproc;
 PLOGINREC login;
 int ncols, x;

 dberrhandle(err_handler);
 dbmsghandle(msg_handler);

 dbinit();
 login = dblogin();
#ifdef HAVE_WINDOWS_H
 DBSETLSECURE(login);
#else
 DBSETLUSER(login, "domain\username");
 DBSETLPWD(login, "password");
#endif


 DBSETLAPP(login, "dblib experiment program");
 dbproc = dbopen(login, "sqlserver");

 dbcmd(dbproc, "SELECT TOP 1 * From [Stats] .. Hourly"); 
 dbsqlexec(dbproc);
 if(dbresults(dbproc) == SUCCEED)
 {
  ncols = dbnumcols(dbproc);
  dbbind(dbproc, 1, NTBSTRINGBIND, 0, temp);

  for(x = 1; x < ncols; x++)
  {
    printf("%s\t", dbcolname(dbproc, x + 1));
  }
  printf("\n");

  while(dbnextrow(dbproc) != NO_MORE_ROWS)
  {
   /* this is the only way to move past any extra rows returned? */
  }

 }

dbfreebuf(dbproc);
#ifdef HAVE_WINDOWS_H
 dbfreelogin(login);
#else
 dbloginfree(login);
#endif
 dbexit();

 return 0;
}

==4311== Memcheck, a memory error detector.
==4311== Copyright (C) 2002-2007, and GNU GPL'd, by Julian Seward et al.
==4311== Using LibVEX rev 1804, a library for dynamic binary translation.
==4311== Copyright (C) 2004-2007, and GNU GPL'd, by OpenWorks LLP.
==4311== Using valgrind-3.3.0-Debian, a dynamic binary instrumentation 
framework.
==4311== Copyright (C) 2000-2007, and GNU GPL'd, by Julian Seward et al.
==4311== For more details, rerun with: -v
==4311==
==4311== Invalid read of size 8
==4311==    at 0x4E33D91: dbdead (dblib.c:4747)
==4311==    by 0x4E33EC9: default_err_handler (dblib.c:4779)
==4311==    by 0x4E313AA: dbperror (dblib.c:7838)
==4311==    by 0x4E3B1F3: dbcmd (dblib.c:1244)
==4311==    by 0x400C5B: main (dblibtest.c:54)
==4311==  Address 0x0 is not stack'd, malloc'd or (recently) free'd
==4311==
==4311== Process terminating with default action of signal 11 (SIGSEGV)
==4311==  Access not within mapped region at address 0x0
==4311==    at 0x4E33D91: dbdead (dblib.c:4747)
==4311==    by 0x4E33EC9: default_err_handler (dblib.c:4779)
==4311==    by 0x4E313AA: dbperror (dblib.c:7838)
==4311==    by 0x4E3B1F3: dbcmd (dblib.c:1244)
==4311==    by 0x400C5B: main (dblibtest.c:54)
==4311==
==4311== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 48 from 6)
==4311== malloc/free: in use at exit: 33,474 bytes in 25 blocks.
==4311== malloc/free: 188 allocs, 163 frees, 224,841 bytes allocated.
==4311== For counts of detected errors, rerun with: -v
==4311== searching for pointers to 25 not-freed blocks.
==4311== checked 167,272 bytes.
==4311==
==4311== LEAK SUMMARY:
==4311==    definitely lost: 292 bytes in 11 blocks.
==4311==      possibly lost: 0 bytes in 0 blocks.
==4311==    still reachable: 33,182 bytes in 14 blocks.
==4311==         suppressed: 0 bytes in 0 blocks.
==4311== Rerun with --leak-check=full to see details of leaked memory.
Segmentation fault



Thanks




More information about the FreeTDS mailing list