Skip to Content.
Sympa Menu

freetds - Re: tds_process_login_tokens()

freetds AT lists.ibiblio.org

Subject: FreeTDS Development Group

List archive

Chronological Thread  
  • From: ZIGLIO Frediano <Frediano.Ziglio AT vodafoneomnitel.it>
  • To: "'TDS Development Group'" <freetds AT franklin.metalab.unc.edu>
  • Subject: Re: tds_process_login_tokens()
  • Date: Wed, 7 Aug 2002 10:14:57 +0200


>
> Ok, I'll explain my methodology for testing memleaks in
> FreeTDS, hopefully
> you'll do the same such that we can figure out where the
> disconnect is.
>
> compiling and running the tsql.c application with dmalloc shows:
>
> ...
> 1028689292: 166: unknown memory: 54 pointers, 7163 bytes
> ...
>
> in the log file.
>
> I use this test program:
>
> [camber@brian tds]$ cat foo.c
> #include <stdio.h>
> #include <netdb.h>
> #include <sys/types.h>
> #include <netinet/in.h>
> #include <arpa/inet.h>
> #ifdef DMALLOC
> #include <dmalloc.h>
> #endif
>
>
> int
> main(int argc, char **argv)
> {
> struct hostent *host = NULL;
>
> host = gethostbyname("localhost");
>
> return 0;
> }
> [camber@brian tds]$
>
> Which I compile in the following manner.
>
> [camber@brian tds]$ gcc -c -o foo.o foo.c -I
> ~/src/dmalloc-4.8.2/ -DDMALLOC
> [camber@brian tds]$ gcc -o foo foo.o -L ~/src/dmalloc-4.8.2/ -ldmalloc
>
> and run, resulting in this log file:
>
> ...
> 1028689495: 62: unknown memory: 52 pointers, 3062 bytes
> ...
>

Perhaps glibc implement gethostbyname in a reentrant way. So it allocate a
per-thread memory and return this memory to application. In thread exit if
free memory (perhaps this is only a problem for main thread)

Perhaps a program that call gethostbyname in a separate thread and join
thread we should see the free..


#include <stdio.h>
#include <netdb.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <pthread.h>
#ifdef DMALLOC
#include <dmalloc.h>
#endif

void*
test(void* arg)
{
struct hostent *host = NULL;

host = gethostbyname("localhost");

return NULL;
}

int
main(int argc, char **argv)
{
pthread_t th;
if (pthread_create(&th,NULL,test,NULL))
return 1;
pthread_join(th,NULL);
return 0;
}

Results: it also allocate 8K for thread (and don't free it), removing
gethostbyname allocate (and not free) only a chunk of 8K. But copying many
time gethostbyname line do not waste other memory.
Replicating also gethostbyname in main do waste other memory. So seem that
glibc allocate some memory at the first call of gethostbyname.

freddy77

=================================
"STRICTLY PERSONAL AND CONFIDENTIAL

This message may contain confidential and proprietary material for the sole
use of the intended recipient. Any review or distribution by others is
strictly prohibited. If you are not the intended recipient please contact
the sender and delete all copies.
The contents of this message that do not relate to the official business of
our company shall be understood as neither given nor endorsed by it."

=================================




Archive powered by MHonArc 2.6.24.

Top of Page