Coder Social home page Coder Social logo

pdcscrn.c - PDC_scr_free about pdcurses HOT 7 OPEN

wmcbrine avatar wmcbrine commented on May 27, 2024
pdcscrn.c - PDC_scr_free

from pdcurses.

Comments (7)

wmcbrine avatar wmcbrine commented on May 27, 2024

You might want to elaborate... but I do see where there might be an issue with the existing code, in the (rare!) case where someone calls delscreen(), and then exits, under X11. (If it's a different situation that you're encounternig, please tell me.)

from pdcurses.

Bill-Gray avatar Bill-Gray commented on May 27, 2024

I think he's trying to avoid a re-free. Better way to do this might be to replace

    if (icon_pixmap)
        XFreePixmap(XCURSESDISPLAY, icon_pixmap);
    if (icon_pixmap_mask)
        XFreePixmap(XCURSESDISPLAY, icon_pixmap_mask);

with

    if (icon_pixmap)
    {
        XFreePixmap(XCURSESDISPLAY, icon_pixmap);
        icon_pixmap = NULL;
    }
    if (icon_pixmap_mask)
    {
        XFreePixmap(XCURSESDISPLAY, icon_pixmap_mask);
        icon_pixmap_mask = NULL;
    }

...i.e., if you free something, set it to NULL so you won't try to free it again.
I vaguely recall running into such issues when using Valgrind to search for memory leaks. As I recall, I got some example code using the VT, WinGui, and I think one other flavor to free all the memory that had been allocated. I couldn't get the X11 flavor to close that cleanly, but didn't really try all that hard. ncurses left lots of memory allocated; apparently, that's a known, won't-fix problem.
The above double-free situation may seem like a 'rare' case. But I do have code that uses

   endwin( );
   getch( );
   initscr( );       /* and further Curses initialization */

so that I can (in ncurses and the VT and WinCon flavors of PDCurses) temporarily show what was on the console before Curses or PDCurses were started.

from pdcurses.

rexx-org avatar rexx-org commented on May 27, 2024

Further to this I get a double free on exiting THE. This is because THE calls XCursesExit() explicitly (because that was the way you had to do it) which calls PDC_scr_free(), and now PDCurses calls PDC_scr_free() atexit the double free occurs.
XCursesExit() should do nothing now.

from pdcurses.

Bill-Gray avatar Bill-Gray commented on May 27, 2024

Mark, I've implemented the solution proposed above for my fork. Does this do the trick for you?
If delscreen(SP) is called, Valgrind finds only one memory leak in the X11 version, from XtVaGetApplicationResources(). I don't know enough about X to know what's going on there or what to do about it.
For SDL1 and SDL2, lots of memory is allocated and never freed. In theory, I can do similar testing for WinCon and WinGUI by running them under Wine through Valgrind, but thus far, I've been unable to get that to work. The VT port appears to be properly freeing everything it allocates.

from pdcurses.

rexx-org avatar rexx-org commented on May 27, 2024

Bill. The link you provide is not to the x11/pdcscrn.c. Besides I am not calling delscreen(), I am calling XCursesExit() only for the x11 build of THE.

from pdcurses.

Bill-Gray avatar Bill-Gray commented on May 27, 2024

(Groan) Sorry, here's the correct link. I kinda confused things by mentioning delscreen(SP) and XtVaGetApplicationResources(); those are both memory leak issues, not double-frees. The pdcscrn.c for X11 that I've posted just addresses the double-free issue you describe, and does so with the common rubric

if( pointer != NULL)   /* don't try freeing it again if it's already been */
{                      /* freed,  or was never alloced in the first place */
    free( pointer);
    pointer = NULL;
}

(repeated several times within my revised PDC_scr_free() for each of the various quantities that that function is expected to free up.)

from pdcurses.

rexx-org avatar rexx-org commented on May 27, 2024

Hi Bill. Yes that works well for me. Thanks.

from pdcurses.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.