From debbugs-submit-bounces@debbugs.gnu.org Wed Jul 05 11:06:15 2017 Received: (at submit) by debbugs.gnu.org; 5 Jul 2017 15:06:15 +0000 Received: from localhost ([127.0.0.1]:53564 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dSlsc-0000ZI-Rl for submit@debbugs.gnu.org; Wed, 05 Jul 2017 11:06:15 -0400 Received: from eggs.gnu.org ([208.118.235.92]:38025) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dSjef-0005j1-Gr for submit@debbugs.gnu.org; Wed, 05 Jul 2017 08:43:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dSjeZ-0006MD-Ai for submit@debbugs.gnu.org; Wed, 05 Jul 2017 08:43:36 -0400 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org X-Spam-Level: X-Spam-Status: No, score=-1.4 required=5.0 tests=BAYES_00,HTML_MESSAGE, RCVD_IN_SORBS_SPAM,T_DKIM_INVALID autolearn=disabled version=3.3.2 Received: from lists.gnu.org ([2001:4830:134:3::11]:46254) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dSjeZ-0006M9-79 for submit@debbugs.gnu.org; Wed, 05 Jul 2017 08:43:35 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57222) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dSjeX-0007q6-ST for bug-gnu-emacs@gnu.org; Wed, 05 Jul 2017 08:43:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dSjeT-0006KW-0M for bug-gnu-emacs@gnu.org; Wed, 05 Jul 2017 08:43:33 -0400 Received: from mxout1.mail.janestreet.com ([38.105.200.78]:49213) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dSjeS-0006Jr-QR for bug-gnu-emacs@gnu.org; Wed, 05 Jul 2017 08:43:28 -0400 Received: from [172.27.56.106] (helo=tot-qpr-mailcore2) by mxout1.mail.janestreet.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.89) (envelope-from ) id 1dSjeR-0000Tf-IQ for bug-gnu-emacs@gnu.org; Wed, 05 Jul 2017 08:43:27 -0400 X-JS-Flow: external X-JS-Scanner-attachment: (ok) No attachments Received: by tot-qpr-mailcore2 with ocaml/mailcore/mailcore 1.0+97 (cbf81801a3e2) (envelope-from ) id BZXN7v-AjPWpP-RY; 2017-07-05 08:43:27.560292-04:00 Received: from mail-qk0-f198.google.com ([209.85.220.198]) by mxgoog1.mail.janestreet.com with esmtps (TLSv1.2:ECDHE-RSA-AES128-GCM-SHA256:128) (Exim 4.89) (envelope-from ) id 1dSjeR-000548-H1 for bug-gnu-emacs@gnu.org; Wed, 05 Jul 2017 08:43:27 -0400 Received: by mail-qk0-f198.google.com with SMTP id g89so115352688qkh.15 for ; Wed, 05 Jul 2017 05:43:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=janestreet.com; s=google; h=mime-version:from:date:message-id:subject:to; bh=YX0Dhva4OA2SA/gkOSsRv1w2YzYharuUFTBNMf7mGDY=; b=GywUMc1lSXn5HOQIrUQBCtwTHtj1VuWZ9ghtpFGNF67oEg0L3oiWfU+EGQZwiKHKKN 0EiKrBq4tGPEHDMH0O+akGfUpTjLub68nCEpZL6IYiPxUF5U9gViM9k9E0oNnH7SkXLS bTKDy3nZFO4hucbQnlQq+Qg3MwRP9VGJx6fQU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=YX0Dhva4OA2SA/gkOSsRv1w2YzYharuUFTBNMf7mGDY=; b=akloAjA/dsmMrviNl/BtzoE5PSB4E1QghpwuRWLvZtxX7zmYxgfut4bwStkZDVyb1E eenCNkEm0/sU/glT+r5rJenWRN7JiHGDYUFFu8hKyzvdYa/7/N0rMidAxPJT4S07edo6 mU8YEyZdeJY2Dm47bjzCzsfS+TMyC9DH5mMWBryXnbSjbia/v0aI9NM9dR945SZzVbsH rqhyUgqew1PGf4MI9uXSjb4KxwIrN3OjgqiFWNoTgHdVYdsRy9FEZuwb5ridTM+FDx6o v1GkQxJO22RwQRJf6pYXd0iFxdFWIBqYM16J/sneyUzg85m7HOBuVrw74Ix/0I7ZhlZt doeQ== X-Gm-Message-State: AIVw111pNKEWSAz0CVasyPWu9SJzXoIeOMva4z221zQoCwi31a2HxPzU EEv9+lNkUge3+3l7TdmaSuYKYtmjkyrqmOB9Ii7ehlJIdIXB+/2lpxeknFpqqvgbR/Pgfm2J8GM 5tJ5icf2GBAq9jJR6nDBE X-Received: by 10.55.95.129 with SMTP id t123mr29204530qkb.119.1499258607144; Wed, 05 Jul 2017 05:43:27 -0700 (PDT) X-Received: by 10.55.95.129 with SMTP id t123mr29204513qkb.119.1499258606871; Wed, 05 Jul 2017 05:43:26 -0700 (PDT) MIME-Version: 1.0 Received: by 10.12.156.10 with HTTP; Wed, 5 Jul 2017 05:43:26 -0700 (PDT) From: Valentin Gatien-Baron Date: Wed, 5 Jul 2017 08:43:26 -0400 Message-ID: Subject: 25.1; in the dynamic modules api, env->free_global_ref doesn't free anything To: bug-gnu-emacs@gnu.org Content-Type: multipart/alternative; boundary="94eb2c055296b08660055391580d" X-JS-Exim-Data-Received: 2017-07-05 08:43:27-0400 X-JS-Processed-by: mailcore X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Received-From: 2001:4830:134:3::11 X-Spam-Score: -3.6 (---) X-Debbugs-Envelope-To: submit X-Mailman-Approved-At: Wed, 05 Jul 2017 11:06:13 -0400 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.6 (---) --94eb2c055296b08660055391580d Content-Type: text/plain; charset="UTF-8" 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 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); } } --94eb2c055296b08660055391580d Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
= The following dynamic module ta= kes unbounded memory:

/* gcc -I . -g = -ggdb -fPIC foo.c -shared -o foo.so && echo running && emac= s -Q -L . -batch -l foo */
#include <emacs-module.h>

int plugin_is_GPL_compatible;

<= /div>
int emacs_module_init(struct emacs_runtime *ert) {
=C2=A0 emac= s_env *env =3D ert->get_environment(ert);
=C2=A0 while (1) {
=C2=A0 =C2=A0 int i;
=C2=A0 =C2=A0 for (i =3D 0; i < = 10000; i++) {
=C2=A0 =C2=A0 =C2=A0 emacs_value v =3D env->make= _string(env, "asdads", 3);
=C2=A0 =C2=A0 =C2=A0 env->= ;free_global_ref(env, env->make_global_ref(env, v));
=C2=A0 = =C2=A0 }
=C2=A0 =C2=A0 env->funcall(env, env->intern(env, &= quot;garbage-collect"), 0, NULL);
=C2=A0 }
}


This is because env->make_global_ref/= env->free_global_ref leak memory.
env->free_global_ref fail= s to remove values from the hash table of
refcounts. The followin= g patch makes the program above run in constant
space.
=

--- src/emacs-module.c 2017-06-30 16:00:36.776301646 -0400
+++ src/emac= s-module.c 2017-06-30 16:05:01.66012= 0043 -0400
@@ -308,7 +308,7 @@
=C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0set_hash_value_slot (h, i, value);
=C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0}
=C2=A0 =C2=A0 =C2=A0 =C2=A0else<= /div>
- hash_remove_from_table (h, valu= e);
+ hash_remove_from_tab= le (h, obj);
=C2=A0 =C2=A0 =C2=A0}
=C2=A0}
=
--94eb2c055296b08660055391580d-- From debbugs-submit-bounces@debbugs.gnu.org Sun Jul 09 18:17:36 2017 Received: (at 27587-done) by debbugs.gnu.org; 9 Jul 2017 22:17:36 +0000 Received: from localhost ([127.0.0.1]:59256 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dUKWG-0004db-9w for submit@debbugs.gnu.org; Sun, 09 Jul 2017 18:17:36 -0400 Received: from mail-oi0-f53.google.com ([209.85.218.53]:36744) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dUKWE-0004dO-LE for 27587-done@debbugs.gnu.org; Sun, 09 Jul 2017 18:17:35 -0400 Received: by mail-oi0-f53.google.com with SMTP id x187so61477004oig.3 for <27587-done@debbugs.gnu.org>; Sun, 09 Jul 2017 15:17:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to; bh=Uu0GEzp4vGonpb5g6YoH/VOz4hD3pGvQhFGuLh4wg2k=; b=ZCJlrn7l7TmkfiwxYOKxqzSeFDyh3UIp4YKDiV06A3zAJVyJfXZAbRPaal3R5L/iyU 5oudbYA1OazSPehePz7B4od8ix01RkZzkiBR8/K0Bw6uk2k+UPLxYvxtTMRdmvhQAfsJ ikLD2mgbMVP9QINgo41MqlR9iL9P3TXU5JiAqnbCiLykIqrd6wk0DMiZ/7NyI6PftsFD IYff0WeRgn2mm/Q9u3DPlFJUGABS8xXRmJt+RjwxjZyVc1zZDy1f68/XfjiB8K8mAeWL KTnFQZKwl/EgDKIucMg+f2ucq0zfkhhR7XrlQZC/v6nlW+PYEwSzPZjadCQYQ67Ofg9C brmg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to; bh=Uu0GEzp4vGonpb5g6YoH/VOz4hD3pGvQhFGuLh4wg2k=; b=UMWVpNL0awF8ww9j39pfDRezib8ogtBlETBk9rgWDXfCqXMAJZwtn9Wf0S1G5SESbR ahutm1Y+CKI12AbOIhrlY4nc5U2YR+zceGCJk9PsVL7FpvE7Q5+e4+e9TbQSswsR5FlS 0dbMx4kjFpWiVwh0VklN7FxDzuztT4RXrNKzIzYnD5b/ndNxDqD+k4OQp5vcFeUIyHGi B8RTGI86SxBHwt+hSX0pImocudCD2hBesePOsLkhEcSrj3tas3HUFu8bbgMt5ep1Rbim 38pjC80mkznqybWA93SKfwQpv/r8KSv6FNzFXya5SqdBp9ly+sWvrX6N+n9xr7FA5bWX k84g== X-Gm-Message-State: AIVw110FJbSR+yI88Syc3Y6en+F1IADZv6pJAscQBpo0Luq3zv1lVBNz qblTsQUewh2CqU9oyw29oBXppCWHtg== X-Received: by 10.202.71.15 with SMTP id u15mr5957747oia.133.1499638647904; Sun, 09 Jul 2017 15:17:27 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Philipp Stephani Date: Sun, 09 Jul 2017 22:17:17 +0000 Message-ID: Subject: Re: bug#27587: 25.1; in the dynamic modules api, env->free_global_ref doesn't free anything To: Valentin Gatien-Baron , 27587-done@debbugs.gnu.org Content-Type: multipart/alternative; boundary="001a113e54cae660870553e9d40c" X-Spam-Score: 0.7 (/) X-Debbugs-Envelope-To: 27587-done X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 0.7 (/) --001a113e54cae660870553e9d40c Content-Type: text/plain; charset="UTF-8" Valentin Gatien-Baron schrieb am Mi., 5. Juli 2017 um 17:07 Uhr: > 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 > > 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); > } > } > > Good catch, installed as 22af69906cca871fdb893e06d6f10dbbab4518e6. --001a113e54cae660870553e9d40c Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable


Valent= in Gatien-Baron <vgatien= -baron@janestreet.com> schrieb am Mi., 5. Juli 2017 um 17:07=C2=A0Uh= r:
The following dynamic module takes unbounded memory:
=
/* gcc -I . -g -ggdb -fPIC foo.c -shared -o foo.s= o && echo running && emacs -Q -L . -batch -l foo */<= br>
#include <emacs-module.h>

int plugin_= is_GPL_compatible;

= int emacs_module_init(struct em= acs_runtime *ert) {
=C2=A0 emacs_env *env =3D ert->get_environ= ment(ert);
=C2=A0 while (1) {
=C2=A0 =C2=A0 int i;
=C2=A0 =C2=A0 for (i =3D 0; i < 10000; i++) {
=C2=A0 =C2= =A0 =C2=A0 emacs_value v =3D env->make_string(env, "asdads", 3= );
=C2=A0 =C2=A0 =C2=A0 env->free_global_ref(env, env->make= _global_ref(env, v));
=C2=A0 =C2=A0 }
=C2=A0 =C2=A0 e= nv->funcall(env, env->intern(env, "garbage-collect"), 0, NU= LL);
=C2=A0 }
}


<= /div>
This is because env->make_global_ref/env->free_global_ref leak mem= ory.
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.
<= font face=3D"arial, helvetica, sans-serif">

=
--= - 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 @@
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0set_h= ash_value_slot (h, i, value);
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0}=
=C2=A0 =C2=A0 =C2=A0 =C2=A0else
- hash_remove_from_table (h, value);
+ hash_remove_from_table (h, obj);
=C2=A0 =C2=A0 =C2=A0}
=C2=A0}

=

Good catch, installed as 22af6= 9906cca871fdb893e06d6f10dbbab4518e6.=C2=A0
--001a113e54cae660870553e9d40c-- From debbugs-submit-bounces@debbugs.gnu.org Mon Jul 10 19:07:57 2017 Received: (at 27587-done) by debbugs.gnu.org; 10 Jul 2017 23:07:57 +0000 Received: from localhost ([127.0.0.1]:33121 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dUhmX-0000gY-1I for submit@debbugs.gnu.org; Mon, 10 Jul 2017 19:07:57 -0400 Received: from mxout1.mail.janestreet.com ([38.105.200.78]:54683) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dUaKD-0002JJ-I6 for 27587-done@debbugs.gnu.org; Mon, 10 Jul 2017 11:10:14 -0400 Received: from [172.27.56.106] (helo=tot-qpr-mailcore2) by mxout1.mail.janestreet.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.89) (envelope-from ) id 1dUaK8-0005dd-1k for 27587-done@debbugs.gnu.org; Mon, 10 Jul 2017 11:10:08 -0400 X-JS-Flow: external X-JS-Scanner-attachment: (ok) No attachments Received: by tot-qpr-mailcore2 with ocaml/mailcore/mailcore 1.0+97 (cbf81801a3e2) (envelope-from ) id BZY5jQ-AjPWpP-BQ; 2017-07-10 11:10:08.045003-04:00 Received: from mail-qt0-f200.google.com ([209.85.216.200]) by mxgoog1.mail.janestreet.com with esmtps (TLSv1.2:ECDHE-RSA-AES128-GCM-SHA256:128) (Exim 4.89) (envelope-from ) id 1dUaK7-0000Nb-W0 for 27587-done@debbugs.gnu.org; Mon, 10 Jul 2017 11:10:08 -0400 Received: by mail-qt0-f200.google.com with SMTP id o3so52370441qto.15 for <27587-done@debbugs.gnu.org>; Mon, 10 Jul 2017 08:10:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=janestreet.com; s=google; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=90urAnqJ1hhAWH4aTjFGyvMbZ7kvp980uMY3gli4CcI=; b=yBd4Bup1jzfUE5YsbV4v8HPwQ6MXXZlWJHgCUd6N1QtuO6BJ8jN4OJbppCjX7EN8fi 65G3BLrrNYwc9ORtPYn/KxUv7+M0tJBtvtvURMG8pCZWec/Gf9OBm1deVEJeIMA56yqT 8qkmofXfMSAd4JOD1cos/zghT61UcbiPvi9FE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=90urAnqJ1hhAWH4aTjFGyvMbZ7kvp980uMY3gli4CcI=; b=AwEesQuCZeee1v+R9S+diBo900FAcGoIia8t35F6Zi1HpeZCZR57nqPLaInFrut/3D IBBQKe7mOGBmLApnI1Q52DL0UrPfBvWP8ssho6PD5eKlxUbXlImzoGsCT7uuGZtC2zCO 4+p40bnoP+VfyVPtem0jTur+WIZGkqQEM4qXr2Zbs2SSgk2zZfajQUPxE3n4XDmE/9dp jN6tBOYkvRnYfOeelk+8i3HDQsNNoZOy87PO9NQdOPiislVQxTR5MD/XPz9OrpyanGAO CjodC/x5FWL/2xmO1NoQ+0bw6TJbwbaAxvvDc2tUtdnBtiYfKIggw4n6//8HC68Q+Dp8 UDFQ== X-Gm-Message-State: AIVw113xqo/HU5bPwi8jlFyY7I3Y3d31DMZQ0H+g6DooW7Wd/KKgi4RB bT2wPNbNfQAGcFHoEOQ1qIC7Euz+ZZ2fVLMVR+PZXjGsq3avEPT/GinxJnJmuGYvsHonK+fUBcN hx0s7mZuKzUiHm58kERkjAJXeBp0= X-Received: by 10.200.53.243 with SMTP id l48mr4947069qtb.7.1499699406207; Mon, 10 Jul 2017 08:10:06 -0700 (PDT) X-Received: by 10.200.53.243 with SMTP id l48mr4946841qtb.7.1499699404537; Mon, 10 Jul 2017 08:10:04 -0700 (PDT) MIME-Version: 1.0 Received: by 10.12.156.10 with HTTP; Mon, 10 Jul 2017 08:10:04 -0700 (PDT) In-Reply-To: References: From: Valentin Gatien-Baron Date: Mon, 10 Jul 2017 11:10:04 -0400 Message-ID: Subject: Re: bug#27587: 25.1; in the dynamic modules api, env->free_global_ref doesn't free anything To: Philipp Stephani Content-Type: multipart/alternative; boundary="001a114574f44c467e0553f7fa6d" X-JS-Exim-Data-Received: 2017-07-10 11:10:08-0400 X-JS-Processed-by: mailcore X-Spam-Score: -1.8 (-) X-Debbugs-Envelope-To: 27587-done X-Mailman-Approved-At: Mon, 10 Jul 2017 19:07:55 -0400 Cc: 27587-done@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.8 (-) --001a114574f44c467e0553f7fa6d Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable =E2=80=8BThanks! By the way, the assert that refcount =3D=3D 0 you added as= a further commit wouldn't have triggered, as the refcount in the hash table would stay at 1 after the call to free_global_ref. On Sun, Jul 9, 2017 at 6:17 PM, Philipp Stephani wrote: > > > Valentin Gatien-Baron schrieb am Mi., 5. > Juli 2017 um 17:07 Uhr: > >> 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 >> >> int plugin_is_GPL_compatible; >> >> int emacs_module_init(struct emacs_runtime *ert) { >> emacs_env *env =3D ert->get_environment(ert); >> while (1) { >> int i; >> for (i =3D 0; i < 10000; i++) { >> emacs_value v =3D 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); >> } >> } >> >> > Good catch, installed as 22af69906cca871fdb893e06d6f10dbbab4518e6. > --001a114574f44c467e0553f7fa6d Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
=E2=80=8BThanks! By the way, the assert that refcount = =3D=3D 0 you added as a further commit wouldn't have triggered, as the = refcount in the hash table would stay at 1 after the call to free_global_re= f.


On Sun, Jul 9, 2017 at 6:17 PM, Philipp Stephani <p.stephani= 2@gmail.com> wrote:


Valentin Gati= en-Baron <vgatien-baron@janestreet.com> schrieb am Mi., 5. Juli 2017 um 17= :07=C2=A0Uhr:
The following dynamic module takes unbounded memory:=

/* gcc -I . -g -ggdb -fPIC foo.c -shar= ed -o foo.so && echo running && emacs -Q -L . -batch -l foo= */
#include <emacs-module.h>

= int plugin_is_GPL_compatible;

int emacs_module_ini= t(struct emacs_runtime *ert) {
=C2=A0 emacs_env *env =3D ert->= get_environment(ert);
=C2=A0 while (1) {
=C2=A0 =C2= =A0 int i;
=C2=A0 =C2=A0 for (i =3D 0; i < 10000; i++) {
=C2=A0 =C2=A0 =C2=A0 emacs_value v =3D env->make_string(env, "= asdads", 3);
=C2=A0 =C2=A0 =C2=A0 env->free_global_ref(en= v, env->make_global_ref(env, v));
=C2=A0 =C2=A0 }
=
= =C2=A0 =C2=A0 env->funcall(env, env->intern(env, "garbage-collec= t"), 0, NULL);
=C2=A0 }
}

<= /div>

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 make= s the program above run in constant
space.

<= /div>

--- src/emacs-module.c 2017-06-30 16:00:36.776301646 -0400
+++ src/emacs-modul= e.c 2017-06-30 16:05:01.6601200= 43 -0400
@@ -308,7 +308,7 @@
=C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0set_hash_value_slot (h, i, value);
=C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0}
=C2=A0 =C2=A0 =C2=A0 =C2=A0else<= /div>
- hash_remove_from_table (h,= value);
+ hash_remov= e_from_table (h, obj);
=C2=A0 =C2=A0 =C2=A0}
=C2=A0}


Good= catch, installed as 22af69906cca871fdb893e06d6f10dbbab4518e6.=C2=A0

--001a114574f44c467e0553f7fa6d-- From unknown Fri Aug 15 03:37:45 2025 Received: (at fakecontrol) by fakecontrolmessage; To: internal_control@debbugs.gnu.org From: Debbugs Internal Request Subject: Internal Control Message-Id: bug archived. Date: Tue, 08 Aug 2017 11:24:05 +0000 User-Agent: Fakemail v42.6.9 # This is a fake control message. # # The action: # bug archived. thanks # This fakemail brought to you by your local debbugs # administrator