[Sussex] ncurses is conspiring against me.

Paul Turner pturner at rentokil.com
Mon May 16 08:02:05 UTC 2005


Captain Redbeard wrote:

> Hi again,
>
> I think I've finally gotten my head around this dynamic memory 
> allocation thing.  I've had to re-design the program from scratch 
> having found some MAJOR design flaws but now I've gotten it up to the 
> point that it contains most of the original data structures and 
> sub-routines with Valgrind reporting zero errors and zero memory 
> leaks.  However, having to that point and being ready to re-code the 
> functionality, I've hit a new problem with the ncurses library that I 
> would to get handled.
>
> Take the following program, it does nothing at all except initialise 
> and clean-up the ncurses library and exits:
>
>
> #include <ncurses.h>
>
> int main()
> {
>   initscr();
>   endwin();
>   return 0;
> }
>
>
> Not very exciting, not very useful.  However, despite its small size, 
> it seems to contain a bug anyway!  The code was compiled with the 
> command "gcc -Wall -o ncurses ncurses.c -lncurses" and compiled and 
> ran fine, however when I checked the program with Valgrind I got the 
> following output:
>
>
> .
> .
> .
> ==22833== malloc/free: in use at exit: 82904 bytes in 162 blocks.
> ==22833== malloc/free: 164 allocs, 2 frees, 82926 bytes allocated.
> .
> .
> .
>
>
> I've looked at whatever info I could find about ncurses, which wasn't 
> a lot, but I don't see any other functions I need to call to avoid 
> this memory leak from occurring.  My question really is is this leak 
> (A) occurring because there is some routine I meant to call but 
> haven't, (B) a bug in ncurses itself or (C) a fact of life that I 
> don't need to worry about and can disregard?
>
> I would like to be able to fix it so that Valgrind reports no unfreed 
> memory as my current philosophy of keeping Valgrind happy has been 
> very successful.  Also, I don't know how I would tell if any leaks 
> reported by Valgrind are occurring because of ncurses calls or because 
> of something I've done so this situation could potentially obscure 
> some genuine bugs on my part.  Any ideas?
>
>
>

Does initscr() have a return value?

Try:

(void) initscr();

instead?

Regards Paul.

-- 

*/Paul Turner/*
Applications Team Leader
*Rentokil Initial* Corporate IT


------------------------------------------------------------------------
Information in this message is confidential and may be privileged. It is 
intended solely for the person(s) to whom it is addressed. If you are 
not the intended recipient, please notify the sender, and please delete 
the message from your system immediately.
------------------------------------------------------------------------


 

_____________________________________________________________________
This message has been checked for all known viruses by 
MessageLabs on behalf of Rentokil Initial plc





More information about the Sussex mailing list