Xpra: Ticket #2451: platform/xposix/appindicator_tray.py leaks a file descriptor in set_icon_from_data

When a new temporary file is created,

self.tmp_filename = tempfile.mkstemp(prefix="tray", suffix=".png", dir=tmp_dir)[1]

a file is opened (and its file descriptor is assigned to the [0] element of that tuple). That file is actually immediately clobbered---it is not used except to avoid races.

That file descriptor can just be immediately closed:

fd,self.tmp_filename = tempfile.mkstemp(prefix="tray", suffix=".png", dir=tmp_dir)

This works (on Linux) and resolves the leak. It resolves an issue that looks like an unresponsive client (in my case right clicking just showed a blank box, with the colored border expected around windows). It failed with an error message like unable to create file descriptor or unable to open file (I've forgotten the exact wording).

Thu, 17 Oct 2019 12:26:47 GMT - Antoine Martin: owner changed

Thanks, applied in r24161.

How about r24162 instead?

Thu, 17 Oct 2019 13:37:57 GMT - aerusso:

Do you think there is any merit in handling, e.g., out of space errors?

fd, self.tmp_filename = tempfile.mkstemp(prefix="tray", suffix=".png", dir=tmp_dir)
    log("set_icon_from_data%s using temporary file %s",
        ("%s pixels" % len(pixels), has_alpha, w, h, rowstride), self.tmp_filename)
    os.write(fd, png_data)
os.fchmod(fd, 0o644)

(Beware untested code.)

Thu, 17 Oct 2019 14:48:00 GMT - Antoine Martin:

Do you think there is any merit in handling, e.g., out of space errors?

r24165 should handle any errors in the section handling IO.

Tue, 22 Oct 2019 08:29:20 GMT - Antoine Martin: status changed; resolution set

Tue, 22 Oct 2019 08:29:52 GMT - Antoine Martin: milestone changed

Sat, 23 Jan 2021 05:51:37 GMT - migration script:

this ticket has been moved to: https://github.com/Xpra-org/xpra/issues/2451