all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* bug#26628: [PATCH] Fix memory leak of cwd string in emacsclient
@ 2017-04-23 19:23 Anders Waldenborg
  2017-04-24  9:23 ` Andreas Schwab
  2017-06-01  6:30 ` Paul Eggert
  0 siblings, 2 replies; 5+ messages in thread
From: Anders Waldenborg @ 2017-04-23 19:23 UTC (permalink / raw)
  To: 26628


[-- Attachment #1.1: Type: text/plain, Size: 60 bytes --]

The attached patch fixes a tiny memory leak in emacsclient.

[-- Attachment #1.2: Type: text/html, Size: 111 bytes --]

[-- Attachment #2: 0001-Fix-memory-leak-of-cwd-string-in-emacsclient.patch --]
[-- Type: text/x-patch, Size: 815 bytes --]

From a673aceab4eb0bcfa4e6ff34c02adc453383805b Mon Sep 17 00:00:00 2001
From: Anders Waldenborg <anders@0x63.nu>
Date: Sun, 23 Apr 2017 21:15:46 +0200
Subject: [PATCH] Fix memory leak of cwd string in emacsclient

* lib-src/emacsclient.c (main): emacsclient retrieves the current
  working directory using get_current_dir_name which returns a newly
  allocated string. Make sure this string is freed before exiting.
---
 lib-src/emacsclient.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/lib-src/emacsclient.c b/lib-src/emacsclient.c
index c22b308..3ffb9ea 100644
--- a/lib-src/emacsclient.c
+++ b/lib-src/emacsclient.c
@@ -1901,6 +1901,8 @@ main (int argc, char **argv)
   if (rl < 0)
     exit_status = EXIT_FAILURE;
 
+  free (cwd);
+
   CLOSE_SOCKET (emacs_socket);
   return exit_status;
 }
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* bug#26628: [PATCH] Fix memory leak of cwd string in emacsclient
  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
  1 sibling, 2 replies; 5+ messages in thread
From: Andreas Schwab @ 2017-04-24  9:23 UTC (permalink / raw)
  To: Anders Waldenborg; +Cc: 26628

On Apr 23 2017, Anders Waldenborg <anders@0x63.nu> wrote:

> * lib-src/emacsclient.c (main): emacsclient retrieves the current
>   working directory using get_current_dir_name which returns a newly
>   allocated string. Make sure this string is freed before exiting.

There is no need to free it since the process exists right away anyway.

Andreas.

-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."





^ permalink raw reply	[flat|nested] 5+ messages in thread

* bug#26628: [PATCH] Fix memory leak of cwd string in emacsclient
  2017-04-24  9:23 ` Andreas Schwab
@ 2017-04-24 16:05   ` Anders Waldenborg
  2017-06-01  2:59   ` npostavs
  1 sibling, 0 replies; 5+ messages in thread
From: Anders Waldenborg @ 2017-04-24 16:05 UTC (permalink / raw)
  To: Andreas Schwab; +Cc: 26628

On Mon, Apr 24, 2017 at 11:23:26AM +0200, Andreas Schwab wrote:
> > * lib-src/emacsclient.c (main): emacsclient retrieves the current
> >   working directory using get_current_dir_name which returns a newly
> >   allocated string. Make sure this string is freed before exiting.
> 
> There is no need to free it since the process exists right away anyway.

Yes. Unless you compile with -fsanitize=address and this leak makes
emacsclient mostly unusable as the asan leak checker will change the
return code to non-zero (yes I'm aware that I can set
ASAN_OPTIONS=detect_leaks=0 in the environment).

 anders





^ permalink raw reply	[flat|nested] 5+ messages in thread

* bug#26628: [PATCH] Fix memory leak of cwd string in emacsclient
  2017-04-24  9:23 ` Andreas Schwab
  2017-04-24 16:05   ` Anders Waldenborg
@ 2017-06-01  2:59   ` npostavs
  1 sibling, 0 replies; 5+ messages in thread
From: npostavs @ 2017-06-01  2:59 UTC (permalink / raw)
  To: Andreas Schwab; +Cc: Anders Waldenborg, 26628

tags 26628 fixed
close 26628 26.1
quit

Andreas Schwab <schwab@linux-m68k.org> writes:

> On Apr 23 2017, Anders Waldenborg <anders@0x63.nu> wrote:
>
>> * lib-src/emacsclient.c (main): emacsclient retrieves the current
>>   working directory using get_current_dir_name which returns a newly
>>   allocated string. Make sure this string is freed before exiting.
>
> There is no need to free it since the process exists right away anyway.

On the other hand, it doesn't really hurt to free it either, pushed to
master [1: c221f1466e].

[1: c221f1466e]: 2017-05-31 22:58:30 -0400
  Fix memory leak of cwd string in emacsclient (Bug#26628)
  http://git.savannah.gnu.org/cgit/emacs.git/commit/?id=c221f1466ed7e0f11f142d9cb3c0247b10e511c6





^ permalink raw reply	[flat|nested] 5+ messages in thread

* bug#26628: [PATCH] Fix memory leak of cwd string in emacsclient
  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-06-01  6:30 ` Paul Eggert
  1 sibling, 0 replies; 5+ messages in thread
From: Paul Eggert @ 2017-06-01  6:30 UTC (permalink / raw)
  To: npostavs; +Cc: Anders Waldenborg, 26628

[-- 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


^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2017-06-01  6:30 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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

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.