Archive for June, 2004

Leak on SQLAPI++

Thursday, June 17th, 2004

I was doing some malloc checking on Solaris today and noticed that I was getting a malloc trap on the auto-detect Sybase library version method of SQLAPI++. You can have the library determine the version of the library in use or you can specify it manually. Up to this point, I've been doing the auto-detection with the code:

    mDBConnection.setOption("CS_VERSION") = "Detect";
    mDBConnection.setOption("CS_APPNAME") = "myApp";
    ...
    mDBConnection.Connect(server, user, password, SA_Sybase_Client);
    ...

but in the Connect() method the malloc checker saw a problem. So, now I'm trying to set the version I know I'm using (12.5) with the code:

    mDBConnection.setOption("CS_VERSION") = "CS_VERSION_125";
    mDBConnection.setOption("CS_APPNAME") = "myApp";
    ...
    mDBConnection.Connect(server, user, password, SA_Sybase_Client);
    ...

Tests are looking much better so far, and that's really encouraging.

Memory Profiling on Solaris

Thursday, June 17th, 2004

OK, memory problems in C and C++ programs are a pain in the rear to find. When you have a massively multi-threaded app they aren't easy to find and that's a real pain. But I've read a nice little bit on a Google search about the watchmalloc library on Solaris.

On Solaris 8 (at least) a man watchmalloc gets you all the information you'll need to figure out how to use it. Basically, it's capable of looking at reads and writes from memory blocks that have already been freed and that's the core of the problem. Any access throws a trap that generates a core dump that can be dealt with in gdb.

To activate it, simply define a few environment variables before running the application:

    setenv LD_PRELOAD watchmalloc.so.1
    setenv MALLOC_DEBUG WATCH,RW

and then you run your app as normal. The WATCH checks for writes to freed memory blocks and the RW does the same for reads. Together, the man pages say this can slow down your app by 1000x - but it's worth it to find the bugger.

I'm running my code with this now and I'm happy to say I think it's found a problem in a third-party library already. That's great news as I can use a work-around to escape this problem.

I hope my luck holds out...