all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Eli Zaretskii <eliz@gnu.org>
To: Alex <agrambot@gmail.com>
Cc: 35179@debbugs.gnu.org
Subject: bug#35179: [PATCH] Plug memory leak in GTK	x-display-monitor-attributes-list
Date: Sun, 07 Apr 2019 19:32:49 +0300	[thread overview]
Message-ID: <83wok593ny.fsf@gnu.org> (raw)
In-Reply-To: <871s2dvpgf.fsf@gmail.com> (message from Alex on Sun, 07 Apr 2019 08:51:12 -0600)

> From: Alex <agrambot@gmail.com>
> Cc: bug-gnu-emacs@gnu.org, 35179@debbugs.gnu.org
> Date: Sun, 07 Apr 2019 08:51:12 -0600
> 
> > I'd prefer to leave g_strdup intact, and instead explicitly release the storage of previous value.  IOW, plug the leak in our own code, not rely on undocumented features which can easily go away some day.
> 
> The documentation of gdk_monitor_get_model[1] specifies that the return
> value is "[transfer none]", which has the description "Don't free data
> after code is done".

That could mean anything.  The only thing it tells us not to call
'free' on the result, but it could be, for example, that the result is
a pointer to a static buffer that can be changed by a subsequent call
to the function.

> The main memory leak, though, was that the MonitorList array wasn't
> being freed.

Does your patch change that?  If not, why not?

> I considered using the free_monitors procedure like the non-GTK
> versions do, but I saw no reason to call g_strdup for each name and
> free each name almost right after.

I don't see how the short lifetime of the array changes anything
here.  As long as we aren't sure the pointer returned by
gdk_monitor_get_model is a copy that cannot be changed by another
thread, we should ourselves make a copy.  Otherwise, who can ensure us
that some other GTK thread doesn't call this same function during the
short life time of the array?

> Since make_monitor_attribute_list uses make_string on each name, I don't
> see any issues that this removal would cause.

The issue I see is that between the time we call gdk_monitor_get_model
and the time we use the string something could change the string to
which the pointer points.  If you can spot something in the GDK docs
that guarantees this couldn't happen, please point me to that piece of
docs.





  reply	other threads:[~2019-04-07 16:32 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-07  5:16 bug#35179: [PATCH] Plug memory leak in GTK x-display-monitor-attributes-list Alex
2019-04-07  6:37 ` Eli Zaretskii
2019-04-07 14:51   ` Alex
2019-04-07 16:32     ` Eli Zaretskii [this message]
2019-04-07 17:34       ` Alex
2019-04-07 17:44         ` Alex
2019-04-07 18:21           ` Eli Zaretskii
2019-04-07 18:52             ` Alex

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=83wok593ny.fsf@gnu.org \
    --to=eliz@gnu.org \
    --cc=35179@debbugs.gnu.org \
    --cc=agrambot@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.