Re: I'm having a crashing problem with FreeTDS under OSX

Frediano Ziglio <[email protected]>
Newsgroups gmane.comp.db.tds.freetds
Message-ID <1236330362.7231.7.camel@freddy>
Il giorno ven, 06/03/2009 alle 00.52 -0500, James K. Lowden ha scritto:
> Daniel Parnell wrote:
> > 	here is the first little bit of the stack trace for the first
> > 	crash  
> > I'm seeing.
> > 
> > Program received signal EXC_BAD_ACCESS, Could not access memory.
> > Reason: KERN_PROTECTION_FAILURE at address: 0x00000016
> > 0x0010f7fa in free ()
> > (gdb) bt
> > #0  0x0010f7fa in free ()
> > #1  0x02f55c38 in _SQLAllocEnv (phenv=0x812c70) at odbc.c:1353
> 
> Bug.  Eh.  The pointer being freed might not have been allocated, and
> isn't zeroed when initialized.  
> 
> 	free(ctx->locale->date_fmt);
> 
> Locale is allocated by tds_alloc_locale() and initialized by
> tds_parse_locale().  Something's a little wrong, because
> tds_parse_locale() should find a proper date format string in
> locales.conf.  In case it doesn't, though, *nothing* initializes the
> memory; it's just pointing to random space.  A little while later, the
> ODBC driver fastidiously frees the tiny string it thinks was allocated,
> and you send a message to the list.  
> 
> I would double-check what's going on with TDSDUMPCONFIG, which should show
> a locales.conf being read and the date_fmt being initialized. But this
> patch wouldn't do any harm:
> 
> RCS file: /cvsroot/freetds/freetds/src/tds/mem.c,v
> retrieving revision 1.175.2.2
> diff -u -r1.175.2.2 mem.c
> --- src/tds/mem.c       5 Nov 2008 14:56:12 -0000       1.175.2.2
> +++ src/tds/mem.c       6 Mar 2009 05:49:34 -0000
> @@ -656,7 +656,7 @@
>  {
>         TDSLOCALE *locale;
>  
> -       TEST_MALLOC(locale, TDSLOCALE);
> +       TEST_CALLOC(locale, TDSLOCALE, 1);
>         return locale;
>  
>        Cleanup:
> 
> HTH.  
> 

#undef TEST_MALLOC
#define TEST_MALLOC(dest,type) \
        {if (!(dest = (type*)calloc(1, sizeof(type)))) goto Cleanup;}


so calloc is called. However I don't understand 0x0000016... memory
corruption ?? Failure to free(NULL) ??

Also consider that in locale.c

  } else if (!strcmp(option, TDS_STR_DATEFMT)) {
    free(locale->date_fmt);
    locale->date_fmt = strdup(value);
  }

so for the same reason you would have a core if locales.conf is found.

But code is so short...

freddy77
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.