all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Paul Eggert <eggert@cs.ucla.edu>
To: npostavs@users.sourceforge.net
Cc: Anders Waldenborg <anders@0x63.nu>, 26628@debbugs.gnu.org
Subject: bug#26628: [PATCH] Fix memory leak of cwd string in emacsclient
Date: Wed, 31 May 2017 23:30:53 -0700	[thread overview]
Message-ID: <6cc3d07a-0387-8d88-4bc2-e127f86b97f7@cs.ucla.edu> (raw)
In-Reply-To: <CADsOX3CMeH-xQd3zRS6k0x=bQeAbbHau=4ruDmk2Xz3CtGzeNA@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 548 bytes --]

Generally speaking we don't bother freeing storage just before program exit 
merely to pacify AddressSanitizer, as that makes the program less efficient and 
is contrary to the goal of leak checking which is to increase efficiency. Here, 
though, we can free storage earlier, and this might have a point since the 
storage can get reused. So I installed the attached further patch.

> I'm aware that I can set ASAN_OPTIONS=detect_leaks=0 in the environment

It might not hurt to do that, if only to prevent our hassling with false alarms.

[-- Attachment #2: 0001-Free-cwd-when-no-longer-needed.txt --]
[-- Type: text/plain, Size: 1395 bytes --]

From 877e808440d4bc2e62d6fb509defee91a3fdc895 Mon Sep 17 00:00:00 2001
From: Paul Eggert <eggert@cs.ucla.edu>
Date: Wed, 31 May 2017 22:38:04 -0700
Subject: [PATCH] Free cwd when no longer needed
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

* lib-src/emacsclient.c (main): Don’t dally when freeing cwd.
---
 lib-src/emacsclient.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/lib-src/emacsclient.c b/lib-src/emacsclient.c
index 3a0715f..8828b76 100644
--- a/lib-src/emacsclient.c
+++ b/lib-src/emacsclient.c
@@ -208,7 +208,7 @@ char *get_current_dir_name (void);
 /* Return the current working directory.  Returns NULL on errors.
    Any other returned value must be freed with free.  This is used
    only when get_current_dir_name is not defined on the system.  */
-char*
+char *
 get_current_dir_name (void)
 {
   char *buf;
@@ -1702,6 +1702,7 @@ main (int argc, char **argv)
   if (tramp_prefix)
     quote_argument (emacs_socket, tramp_prefix);
   quote_argument (emacs_socket, cwd);
+  free (cwd);
   send_to_emacs (emacs_socket, "/");
   send_to_emacs (emacs_socket, " ");
 
@@ -1945,8 +1946,6 @@ main (int argc, char **argv)
   if (rl < 0)
     exit_status = EXIT_FAILURE;
 
-  free (cwd);                   /* Keep leak checkers happy.  */
-
   CLOSE_SOCKET (emacs_socket);
   return exit_status;
 }
-- 
2.7.4


      parent reply	other threads:[~2017-06-01  6:30 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-04-23 19:23 bug#26628: [PATCH] Fix memory leak of cwd string in emacsclient Anders Waldenborg
2017-04-24  9:23 ` Andreas Schwab
2017-04-24 16:05   ` Anders Waldenborg
2017-06-01  2:59   ` npostavs
2017-06-01  6:30 ` Paul Eggert [this message]

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=6cc3d07a-0387-8d88-4bc2-e127f86b97f7@cs.ucla.edu \
    --to=eggert@cs.ucla.edu \
    --cc=26628@debbugs.gnu.org \
    --cc=anders@0x63.nu \
    --cc=npostavs@users.sourceforge.net \
    /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.