• XDestroyImage()

    From Muttley@Muttley@dastardlyhq.com to comp.unix.programmer,comp.windows.x on Sun Nov 12 15:59:36 2023
    From Newsgroup: comp.windows.x

    Hello

    I'm a bit uncertain from the man page and from googling around whether XDestroyImage() only frees the XImage structure created by XCreateImage()
    or whether it also frees the user allocated memory that gets passed into XCreateImage().

    Anyone know?

    Thanks for any help

    --- Synchronet 3.21d-Linux NewsLink 1.2
  • From kalevi@kalevi@kolttonen.fi (Kalevi Kolttonen) to comp.unix.programmer,comp.windows.x on Sun Nov 12 16:20:09 2023
    From Newsgroup: comp.windows.x

    In comp.unix.programmer Muttley@dastardlyhq.com wrote:
    I'm a bit uncertain from the man page and from googling around whether XDestroyImage() only frees the XImage structure created by XCreateImage()
    or whether it also frees the user allocated memory that gets passed into XCreateImage().

    I just did the following on Fedora Linux 39:

    dnf download --source libX11-devel
    rpm2cpio libX11-1.8.7-1.fc39.src.rpm | cpio -idm
    unxz libX11-1.8.7.tar.xz
    tar xvf libX11-1.8.7.tar

    and some quick grepping. Here are the relevant results:

    int
    XDestroyImage(
    XImage *ximage)
    {
    return((*((ximage)->f.destroy_image))((ximage)));
    }


    image->f.destroy_image = _XDestroyImage;


    static int _XDestroyImage (XImage *ximage)
    {
    Xfree(ximage->data);
    Xfree(ximage->obdata);
    Xfree(ximage);
    return 1;
    }

    So yes, the user allocated data gets freed by
    XDestroyImage().

    br,
    KK
    --- Synchronet 3.21d-Linux NewsLink 1.2
  • From Muttley@Muttley@dastardlyhq.com to comp.unix.programmer,comp.windows.x on Sun Nov 12 16:30:14 2023
    From Newsgroup: comp.windows.x

    On Sun, 12 Nov 2023 16:20:09 -0000 (UTC)
    kalevi@kolttonen.fi (Kalevi Kolttonen) wrote:
    In comp.unix.programmer Muttley@dastardlyhq.com wrote:
    I'm a bit uncertain from the man page and from googling around whether
    XDestroyImage() only frees the XImage structure created by XCreateImage()
    or whether it also frees the user allocated memory that gets passed into
    XCreateImage().

    I just did the following on Fedora Linux 39:

    dnf download --source libX11-devel
    rpm2cpio libX11-1.8.7-1.fc39.src.rpm | cpio -idm
    unxz libX11-1.8.7.tar.xz
    tar xvf libX11-1.8.7.tar

    and some quick grepping. Here are the relevant results:

    int
    XDestroyImage(
    XImage *ximage)
    {
    return((*((ximage)->f.destroy_image))((ximage)));
    }


    image->f.destroy_image = _XDestroyImage;


    static int _XDestroyImage (XImage *ximage)
    {
    Xfree(ximage->data);
    Xfree(ximage->obdata);
    Xfree(ximage);
    return 1;
    }

    So yes, the user allocated data gets freed by
    XDestroyImage().

    Thanks. Seems a bit inconsistent that XCreateImage() can't allocate but then thats Xlib for you.

    --- Synchronet 3.21d-Linux NewsLink 1.2
  • From James Kuyper@jameskuyper@alumni.caltech.edu to comp.unix.programmer,comp.windows.x on Sun Nov 12 12:24:25 2023
    From Newsgroup: comp.windows.x

    In comp.unix.programmer Muttley@dastardlyhq.com wrote:
    I'm a bit uncertain from the man page and from googling around whether XDestroyImage() only frees the XImage structure created by XCreateImage()
    or whether it also frees the user allocated memory that gets passed into XCreateImage().

    The man page that I found describing the XDestroyImage macro says, quite prominently:

    "Note that when the image is created using XCreateImage(), XGetImage(),
    or XSubImage(), the destroy procedure that this macro calls frees both
    the image structure and the data pointed to by the image structure."

    Does the manpage you viewed lack that statement?
    --- Synchronet 3.21d-Linux NewsLink 1.2
  • From scott@scott@slp53.sl.home (Scott Lurndal) to comp.unix.programmer,comp.windows.x on Sun Nov 12 17:34:34 2023
    From Newsgroup: comp.windows.x

    Muttley@dastardlyhq.com writes:
    Hello

    I'm a bit uncertain from the man page and from googling around whether >XDestroyImage() only frees the XImage structure created by XCreateImage()
    or whether it also frees the user allocated memory that gets passed into >XCreateImage().

    Anyone know?

    Kalevi answered.

    To obtain an answer this question you could have run the application under valgrind - it would tell you about any memory that hadn't been
    deallocated at exit (using the leak check option).

    --- Synchronet 3.21d-Linux NewsLink 1.2
  • From candycanearter07@no@thanks.net to comp.unix.programmer,comp.windows.x on Sun Nov 12 19:11:52 2023
    From Newsgroup: comp.windows.x

    On 11/12/23 11:34, Scott Lurndal wrote:
    Muttley@dastardlyhq.com writes:
    Hello

    I'm a bit uncertain from the man page and from googling around whether
    XDestroyImage() only frees the XImage structure created by XCreateImage()
    or whether it also frees the user allocated memory that gets passed into
    XCreateImage().

    Anyone know?

    Kalevi answered.

    To obtain an answer this question you could have run the application under valgrind - it would tell you about any memory that hadn't been
    deallocated at exit (using the leak check option).


    Or, you could set the user memory to a stack variable and see what happens.
    --
    user <candycane> is generated from /dev/urandom

    --- Synchronet 3.21d-Linux NewsLink 1.2
  • From Muttley@Muttley@dastardlyhq.com to comp.unix.programmer,comp.windows.x on Mon Nov 13 11:05:55 2023
    From Newsgroup: comp.windows.x

    On Sun, 12 Nov 2023 12:24:25 -0500
    James Kuyper <jameskuyper@alumni.caltech.edu> wrote:
    In comp.unix.programmer Muttley@dastardlyhq.com wrote:
    I'm a bit uncertain from the man page and from googling around whether
    XDestroyImage() only frees the XImage structure created by XCreateImage()
    or whether it also frees the user allocated memory that gets passed into
    XCreateImage().

    The man page that I found describing the XDestroyImage macro says, quite >prominently:

    "Note that when the image is created using XCreateImage(), XGetImage(),
    or XSubImage(), the destroy procedure that this macro calls frees both
    the image structure and the data pointed to by the image structure."

    Does the manpage you viewed lack that statement?

    Yes. All it says is:

    "The XDestroyImage function deallocates the memory associated with the
    XImage structure."

    Which is ambiguous.

    --- Synchronet 3.21d-Linux NewsLink 1.2
  • From Muttley@Muttley@dastardlyhq.com to comp.unix.programmer,comp.windows.x on Mon Nov 13 11:06:28 2023
    From Newsgroup: comp.windows.x

    On Sun, 12 Nov 2023 17:34:34 GMT
    scott@slp53.sl.home (Scott Lurndal) wrote:
    Muttley@dastardlyhq.com writes:
    Hello

    I'm a bit uncertain from the man page and from googling around whether >>XDestroyImage() only frees the XImage structure created by XCreateImage() >>or whether it also frees the user allocated memory that gets passed into >>XCreateImage().

    Anyone know?

    Kalevi answered.

    To obtain an answer this question you could have run the application under >valgrind - it would tell you about any memory that hadn't been
    deallocated at exit (using the leak check option).

    I'd have to install valgrind first. Life's too short.

    --- Synchronet 3.21d-Linux NewsLink 1.2
  • From scott@scott@slp53.sl.home (Scott Lurndal) to comp.unix.programmer,comp.windows.x on Mon Nov 13 14:59:22 2023
    From Newsgroup: comp.windows.x

    Muttley@dastardlyhq.com writes:
    On Sun, 12 Nov 2023 17:34:34 GMT
    scott@slp53.sl.home (Scott Lurndal) wrote:
    Muttley@dastardlyhq.com writes:
    Hello

    I'm a bit uncertain from the man page and from googling around whether >>>XDestroyImage() only frees the XImage structure created by XCreateImage() >>>or whether it also frees the user allocated memory that gets passed into >>>XCreateImage().

    Anyone know?

    Kalevi answered.

    To obtain an answer this question you could have run the application under >>valgrind - it would tell you about any memory that hadn't been
    deallocated at exit (using the leak check option).

    I'd have to install valgrind first. Life's too short.


    sudo apt -y install valgrind
    yum install valgrind

    not too short for that.
    --- Synchronet 3.21d-Linux NewsLink 1.2
  • From Muttley@Muttley@dastardlyhq.com to comp.unix.programmer,comp.windows.x on Mon Nov 13 15:57:07 2023
    From Newsgroup: comp.windows.x

    On Mon, 13 Nov 2023 14:59:22 GMT
    scott@slp53.sl.home (Scott Lurndal) wrote:
    Muttley@dastardlyhq.com writes:
    On Sun, 12 Nov 2023 17:34:34 GMT
    scott@slp53.sl.home (Scott Lurndal) wrote:
    Muttley@dastardlyhq.com writes:
    Hello

    I'm a bit uncertain from the man page and from googling around whether >>>>XDestroyImage() only frees the XImage structure created by XCreateImage() >>>>or whether it also frees the user allocated memory that gets passed into >>>>XCreateImage().

    Anyone know?

    Kalevi answered.

    To obtain an answer this question you could have run the application under >>>valgrind - it would tell you about any memory that hadn't been >>>deallocated at exit (using the leak check option).

    I'd have to install valgrind first. Life's too short.


    sudo apt -y install valgrind
    yum install valgrind

    not too short for that.

    fenris$ yum
    -bash: yum: command not found

    Its a Mac so I'd probably have to piss about with Brew. Like I said, lifes
    too short.

    --- Synchronet 3.21d-Linux NewsLink 1.2
  • From Winston@wbe@UBEBLOCK.psr.com.invalid to comp.unix.programmer,comp.windows.x on Mon Nov 13 11:53:54 2023
    From Newsgroup: comp.windows.x

    Muttley@dastardlyhq.com writes:
    On Sun, 12 Nov 2023 12:24:25 -0500
    James Kuyper <jameskuyper@alumni.caltech.edu> wrote:
    In comp.unix.programmer Muttley@dastardlyhq.com wrote:
    I'm a bit uncertain from the man page and from googling around whether
    XDestroyImage() only frees the XImage structure created by XCreateImage() >>> or whether it also frees the user allocated memory that gets passed into >>> XCreateImage().

    The man page that I found describing the XDestroyImage macro says, quite >>prominently:

    "Note that when the image is created using XCreateImage(), XGetImage(),
    or XSubImage(), the destroy procedure that this macro calls frees both
    the image structure and the data pointed to by the image structure."

    Does the manpage you viewed lack that statement?

    Yes. All it says is:

    "The XDestroyImage function deallocates the memory associated with the XImage structure."

    Which is ambiguous.

    Check your man page again. Yes, the description of XDestroyImage just
    before SEE ALSO says only what you quoted, but, on my libX11 1.8.7
    version of the man page, the paragraph James quoted ("Note that ...") is
    above, at the 5th paragraph, right after the XCreateImage paragraph.
    -WBE
    --- Synchronet 3.21d-Linux NewsLink 1.2
  • From Keith Thompson@Keith.S.Thompson+u@gmail.com to comp.unix.programmer,comp.windows.x on Mon Nov 13 11:35:27 2023
    From Newsgroup: comp.windows.x

    Muttley@dastardlyhq.com writes:
    On Sun, 12 Nov 2023 12:24:25 -0500
    James Kuyper <jameskuyper@alumni.caltech.edu> wrote:
    In comp.unix.programmer Muttley@dastardlyhq.com wrote:
    I'm a bit uncertain from the man page and from googling around whether
    XDestroyImage() only frees the XImage structure created by XCreateImage() >>> or whether it also frees the user allocated memory that gets passed into >>> XCreateImage().

    The man page that I found describing the XDestroyImage macro says, quite >>prominently:

    "Note that when the image is created using XCreateImage(), XGetImage(),
    or XSubImage(), the destroy procedure that this macro calls frees both
    the image structure and the data pointed to by the image structure."

    Does the manpage you viewed lack that statement?

    Yes. All it says is:

    "The XDestroyImage function deallocates the memory associated with the XImage structure."

    Which is ambiguous.

    That's very surprising. Looking at a Git mirror of libX11 (https://github.com/mirror/libX11), that "Note that" paragraph appears
    in every version of that man page going back to 2003 (X11R6.6).

    On my system, Ubuntu 22.04, I get:

    $ man XDestroyImage | wc -l
    139
    $ man XDestroyImage | tail -n 1
    X Version 11 libX11 1.7.5 XCreateImage(3) $ man XDestroyImage | sed -n '/Note that/,+3p'
    Note that when the image is created using XCreateImage, XGetImage, or
    XSubImage, the destroy procedure that the XDestroyImage function calls
    frees both the image structure and the data pointed to by the image
    structure.
    $

    What do you get on your system? (You mentioned that you're on a Mac.)

    See also https://linux.die.net/man/3/xdestroyimage

    (Note that the XDestroyImage man page is typically a symlink to the
    XInitImage man page.)
    --
    Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
    Will write code for food.
    void Void(void) { Void(); } /* The recursive call of the void */
    --- Synchronet 3.21d-Linux NewsLink 1.2
  • From Ben Bacarisse@ben.usenet@bsb.me.uk to comp.unix.programmer,comp.windows.x on Wed Nov 15 12:32:33 2023
    From Newsgroup: comp.windows.x

    Keith Thompson <Keith.S.Thompson+u@gmail.com> writes:

    Muttley@dastardlyhq.com writes:
    On Sun, 12 Nov 2023 12:24:25 -0500
    James Kuyper <jameskuyper@alumni.caltech.edu> wrote:
    In comp.unix.programmer Muttley@dastardlyhq.com wrote:
    I'm a bit uncertain from the man page and from googling around whether >>>> XDestroyImage() only frees the XImage structure created by XCreateImage() >>>> or whether it also frees the user allocated memory that gets passed into >>>> XCreateImage().

    The man page that I found describing the XDestroyImage macro says, quite >>>prominently:

    "Note that when the image is created using XCreateImage(), XGetImage(), >>>or XSubImage(), the destroy procedure that this macro calls frees both >>>the image structure and the data pointed to by the image structure."

    Does the manpage you viewed lack that statement?

    Yes. All it says is:

    "The XDestroyImage function deallocates the memory associated with the
    XImage structure."

    Which is ambiguous.

    That's very surprising. Looking at a Git mirror of libX11 (https://github.com/mirror/libX11), that "Note that" paragraph appears
    in every version of that man page going back to 2003 (X11R6.6).

    On my system, Ubuntu 22.04, I get:

    $ man XDestroyImage | wc -l
    139
    $ man XDestroyImage | tail -n 1
    X Version 11 libX11 1.7.5 XCreateImage(3)
    $ man XDestroyImage | sed -n '/Note that/,+3p'
    Note that when the image is created using XCreateImage, XGetImage, or
    XSubImage, the destroy procedure that the XDestroyImage function calls
    frees both the image structure and the data pointed to by the image
    structure.
    $

    What do you get on your system? (You mentioned that you're on a Mac.)

    Just as a random data point, on a Mac I have access to (but don't
    understand well enough to say anything reliable about what software it
    has installed) I get this:

    $ man XDestroyImage | wc -l
    140
    $ man XDestroyImage | tail -n 1
    X Version 11 libX11 1.5.0 XCreateImage(3) $ man XDestroyImage | sed -n '/Note that/,+3p'
    Note that when the image is created using XCreateImage, XGetImage, or
    XSubImage, the destroy procedure that the XDestroyImage function calls
    frees both the image structure and the data pointed to by the image
    structure.
    --
    Ben.
    --- Synchronet 3.21d-Linux NewsLink 1.2