From: Valentin Gatien-Baron <vgatien-baron@janestreet.com>
To: 27587@debbugs.gnu.org
Subject: bug#27587: 25.1; in the dynamic modules api, env->free_global_ref doesn't free anything
Date: Wed, 5 Jul 2017 08:43:26 -0400 [thread overview]
Message-ID: <CAFd54qM42gO7-mpa7=Q3+0b=i6HmfBE4toSFmTDY91v+8n-6nw@mail.gmail.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 1080 bytes --]
The following dynamic module takes unbounded memory:
/* gcc -I . -g -ggdb -fPIC foo.c -shared -o foo.so && echo running && emacs
-Q -L . -batch -l foo */
#include <emacs-module.h>
int plugin_is_GPL_compatible;
int emacs_module_init(struct emacs_runtime *ert) {
emacs_env *env = ert->get_environment(ert);
while (1) {
int i;
for (i = 0; i < 10000; i++) {
emacs_value v = env->make_string(env, "asdads", 3);
env->free_global_ref(env, env->make_global_ref(env, v));
}
env->funcall(env, env->intern(env, "garbage-collect"), 0, NULL);
}
}
This is because env->make_global_ref/env->free_global_ref leak memory.
env->free_global_ref fails to remove values from the hash table of
refcounts. The following patch makes the program above run in constant
space.
--- src/emacs-module.c 2017-06-30 16:00:36.776301646 -0400
+++ src/emacs-module.c 2017-06-30 16:05:01.660120043 -0400
@@ -308,7 +308,7 @@
set_hash_value_slot (h, i, value);
}
else
- hash_remove_from_table (h, value);
+ hash_remove_from_table (h, obj);
}
}
[-- Attachment #2: Type: text/html, Size: 4437 bytes --]
next reply other threads:[~2017-07-05 12:43 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-07-05 12:43 Valentin Gatien-Baron [this message]
2017-07-09 22:17 ` bug#27587: 25.1; in the dynamic modules api, env->free_global_ref doesn't free anything Philipp Stephani
2017-07-10 15:10 ` Valentin Gatien-Baron
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='CAFd54qM42gO7-mpa7=Q3+0b=i6HmfBE4toSFmTDY91v+8n-6nw@mail.gmail.com' \
--to=vgatien-baron@janestreet.com \
--cc=27587@debbugs.gnu.org \
/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.