• XDestroyImage()

    From Muttley@dastardlyhq.com@21:1/5 to All on Sun Nov 12 15:59:36 2023
    XPost: 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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Muttley@dastardlyhq.com@21:1/5 to Kalevi Kolttonen on Sun Nov 12 16:30:14 2023
    XPost: 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.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Kalevi Kolttonen@21:1/5 to Muttley@dastardlyhq.com on Sun Nov 12 16:20:09 2023
    XPost: 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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From James Kuyper@21:1/5 to Muttley@dastardlyhq.com on Sun Nov 12 12:24:25 2023
    XPost: 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?

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Scott Lurndal@21:1/5 to Muttley@dastardlyhq.com on Sun Nov 12 17:34:34 2023
    XPost: 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).

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From candycanearter07@21:1/5 to Scott Lurndal on Sun Nov 12 19:11:52 2023
    XPost: 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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Muttley@dastardlyhq.com@21:1/5 to Scott Lurndal on Mon Nov 13 11:06:28 2023
    XPost: 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.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Muttley@dastardlyhq.com@21:1/5 to James Kuyper on Mon Nov 13 11:05:55 2023
    XPost: 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.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Scott Lurndal@21:1/5 to Muttley@dastardlyhq.com on Mon Nov 13 14:59:22 2023
    XPost: 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.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Muttley@dastardlyhq.com@21:1/5 to Scott Lurndal on Mon Nov 13 15:57:07 2023
    XPost: 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.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Winston@21:1/5 to Muttley@dastardlyhq.com on Mon Nov 13 11:53:54 2023
    XPost: 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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Keith Thompson@21:1/5 to Muttley@dastardlyhq.com on Mon Nov 13 11:35:27 2023
    XPost: 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 */

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Nicolas George@21:1/5 to All on Tue Nov 14 16:12:48 2023
    Muttley@dastardlyhq.com, dans le message <uisvvk$kdq5$1@dont-email.me>,
    a écrit :
    I'd have to install valgrind first. Life's too short.

    Life's too short to debug WITHOUT valgrind.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Ben Bacarisse@21:1/5 to Keith Thompson on Wed Nov 15 12:32:33 2023
    XPost: 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.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From candycanearter07@21:1/5 to Nicolas George on Wed Nov 15 11:35:57 2023
    On 11/14/23 10:12, Nicolas George wrote:
    Muttley@dastardlyhq.com, dans le message <uisvvk$kdq5$1@dont-email.me>,
    a écrit :
    I'd have to install valgrind first. Life's too short.

    Life's too short to debug WITHOUT valgrind.

    And gdb is also pretty useful (if you compile with -ggdb).
    --
    user <candycane> is generated from /dev/urandom

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Muttley@dastardlyhq.com@21:1/5 to no@thanks.net on Thu Nov 16 08:51:54 2023
    On Wed, 15 Nov 2023 11:35:57 -0600
    candycanearter07 <no@thanks.net> wrote:
    On 11/14/23 10:12, Nicolas George wrote:
    Muttley@dastardlyhq.com, dans le message <uisvvk$kdq5$1@dont-email.me>,
    a écrit :
    I'd have to install valgrind first. Life's too short.

    Life's too short to debug WITHOUT valgrind.

    And gdb is also pretty useful (if you compile with -ggdb).

    -fsanitize=address is probably the most useful runtime debugging option in recent times IMO.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From candycanearter07@21:1/5 to Muttley@dastardlyhq.com on Sun Nov 19 21:07:42 2023
    On 11/16/23 02:51, Muttley@dastardlyhq.com wrote:
    On Wed, 15 Nov 2023 11:35:57 -0600
    candycanearter07 <no@thanks.net> wrote:
    On 11/14/23 10:12, Nicolas George wrote:
    Muttley@dastardlyhq.com, dans le message <uisvvk$kdq5$1@dont-email.me>,
    a écrit :
    I'd have to install valgrind first. Life's too short.

    Life's too short to debug WITHOUT valgrind.

    And gdb is also pretty useful (if you compile with -ggdb).

    -fsanitize=address is probably the most useful runtime debugging option in recent times IMO.



    True, I keep forgetting to add it tho
    --
    user <candycane> is generated from /dev/urandom

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)