Re: strange problem with MySQL

From: Bjørn Augestad (boa_at_metasystems.no)
Date: 11/26/05


Date: Sat, 26 Nov 2005 17:29:12 +0100

Roman Mashak wrote:
> Hello, Bjørn!
> You wrote on Sat, 26 Nov 2005 07:01:30 +0100:
>
> ??>> {
> ??>> MYSQL *c;
> BA> (Disclaimer: I am not familiar with MySQL)
> BA> 1. Why do you create the variable c? Can't you just use Conn instead?
> BA> 2. Why do you allocate c on the heap instead of the stack? Saves you
> BA> a lot of of calls to free().
> What do you mean here? Could you please clarify?
Sure. It looked to me as the variable named c wasn't needed. IIRC all
the code did was to create c and copy conn to c. Then the code used some
members (username/password) from c to connect to the database. Unless
the mysql functions modify its arguments, c can be replaced with conn.

>
> BA> Hard to tell. Have you tried to run valgrind(http://valgrind.kde.org)
> BA> on your executable? If not, do that first. Valgrind will find the
> BA> error, guaranteed. It is so good it takes all the fun out of debugging
> BA> ;-)
> Is is a sort of 'slint' ?
Sort of, but not really. Splint analyzes source code and valgrind
analyzes program behaviour at runtime.

To quote its web site:
"Valgrind is an award-winning suite of tools for debugging and profiling
Linux programs. With the tools that come with Valgrind, you can
automatically detect many memory management and threading bugs, avoiding
hours of frustrating bug-hunting, making your programs more stable. You
can also perform detailed profiling, to speed up and reduce memory use
of your programs."

IMO no one should code C/C++ on Linux without using valgrind.

Bjørn



Relevant Pages

  • Re: Valgrind magically fixes my error
    ... > thing I do is run the program through gdb, ... > hence a segfault when it is dereferenced. ... > The problem is that whenever I run my program through valgrind, ... Different memory management, as you mention, could also be a factor. ...
    (comp.unix.programmer)
  • Re: Ask for any freeware memory leakage tools
    ... "Valgrind is an award-winning suite of tools for debugging and profiling ... Linux programs. ... to speed up and reduce memory use of your ...
    (comp.software.testing)