* tta/C/main/parser_conf.c (unregister_parser_conf_descriptor): reset
global_parser_conf to NULL and then free parser_conf itself.

* tta/C/parsetexi/set_parser_conf.c (reset_parser_conf):
global_parser_conf NULL may now also happen when registered and
unregistered from SWIG.  So clear simple_parser_conf if
global_parser_conf was NULL, in case we are in this situation.
diff --git a/ChangeLog b/ChangeLog
index 7082f98..e159ce6 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2026-12-04  Patrice Dumas  <pertusus@free.fr>
+
+	* tta/C/main/parser_conf.c (unregister_parser_conf_descriptor): reset
+	global_parser_conf to NULL and then free parser_conf itself.
+
+	* tta/C/parsetexi/set_parser_conf.c (reset_parser_conf):
+	global_parser_conf NULL may now also happen when registered and
+	unregistered from SWIG.  So clear simple_parser_conf if
+	global_parser_conf was NULL, in case we are in this situation.
+
 2026-12-03  Patrice Dumas  <pertusus@free.fr>
 
 	* tta/C/api_for_swig/swig_interface.c: add const to the functions used
diff --git a/tta/C/main/parser_conf.c b/tta/C/main/parser_conf.c
index 6d3ec64..025e245 100644
--- a/tta/C/main/parser_conf.c
+++ b/tta/C/main/parser_conf.c
@@ -14,7 +14,7 @@
    along with this program.  If not, see <https://www.gnu.org/licenses/>. */
 
 /* This file is in main and not in parsetexi because get_perl_info.c depends
-   on it */
+   on it and also because it is used in the SWIG interface */
 
 #include <config.h>
 #include <stdlib.h>
@@ -26,7 +26,7 @@
 #include "utils.h"
 #include "parser_conf.h"
 
-/* Configuration values.  This global variables is used in the parser
+/* Configuration values.  This global variable is used in the parser
    code. */
 PARSER_CONF *global_parser_conf;
 
@@ -36,15 +36,26 @@
 static size_t parser_conf_space;
 
 /* NOTE the registered parser configurations are never unallocated.
-   The conf memory use is not important.  Also, there is no parser
-   configuration allocated thought gdt (with accept_internalvalue
-   set being used as an indication that the parser is setup from gdt,
-   as seen in Perl code).  Therefore, there is only one conf allocated
-   per converted file in the main program, which means a very low need
-   of memory for the confs.  In the *.t tests there is one registered
-   conf per test, but it is not an issue as it is for tests. */
+   The conf memory use is not important.
 
+   The parser configuration is never registered nor reused when parsing
+   is called from the C main program.
 
+   When called from XS, there is no parser configuration allocated through
+   a Parser setup from gdt (with accept_internalvalue set being used as
+   an indication that the parser is setup from gdt, as seen in Perl code).
+   Therefore, there is only one conf allocated per parsed file in the main
+   Perl program, which means a very low need of memory for the confs.
+   In the *.t tests there is one registered conf per test, but it is not
+   an issue as it is for tests.
+
+   When called from the SWIG interface, there is a parser configuration
+   added when creating the parser, which should be removed when the parser
+   is destroyed by the caller.  Still no parser configuration registered
+   nor reused with gdt.
+ */
+
+/* called from XS and from the SWIG interface */
 PARSER_CONF *
 retrieve_parser_conf (size_t parser_conf_descriptor)
 {
@@ -54,6 +65,7 @@
   return 0;
 }
 
+/* called from XS and from the SWIG interface */
 PARSER_CONF *
 register_conf (void)
 {
@@ -115,6 +127,7 @@
   free (parser_conf->values.list);
 }
 
+/* called from the SWIG interface */
 void
 unregister_parser_conf_descriptor (size_t parser_conf_descriptor)
 {
@@ -122,10 +135,16 @@
   if (parser_conf)
     {
       free_parser_conf (parser_conf);
+      /* if global_parser_conf was not reset, it would be accessed while still
+         pointing to released memory after parser_conf is free'd. */
+      if (parser_conf == global_parser_conf)
+        global_parser_conf = 0;
+      free (parser_conf);
       parser_conf_list[parser_conf_descriptor -1] = 0;
     }
 }
 
+/* called from XS and from the SWIG interface */
 void
 apply_conf (PARSER_CONF *parser_conf)
 {
diff --git a/tta/C/parsetexi/set_parser_conf.c b/tta/C/parsetexi/set_parser_conf.c
index a1325e2..755c760 100644
--- a/tta/C/parsetexi/set_parser_conf.c
+++ b/tta/C/parsetexi/set_parser_conf.c
@@ -171,8 +171,18 @@
         */
     }
   else
-    /* in that case global_parser_conf has never been set, it is still NULL */
-    global_parser_conf = &simple_parser_conf;
+    /* in that case global_parser_conf has never been set, it is still NULL,
+       or it was registered and afterwards unregistered and free'd (from
+       the SWIG interface).
+     */
+    {
+      global_parser_conf = &simple_parser_conf;
+      /* needed if global_parser_conf has already been set (and
+         registered).  simple_parser_conf, that was copied over to
+         the registered configuration is cleared and reused.
+       */
+      memset (global_parser_conf, 0, sizeof (PARSER_CONF));
+    }
 
   global_parser_conf->descriptor = 0;