[sr-dev] git:master:58047ba6: app_perl: first destroy old interpreter before creating the new one

Daniel-Constantin Mierla miconda at gmail.com
Wed Oct 2 08:34:19 CEST 2019


Module: kamailio
Branch: master
Commit: 58047ba61d0cbceebc8c85590970a573fc396aa5
URL: https://github.com/kamailio/kamailio/commit/58047ba61d0cbceebc8c85590970a573fc396aa5

Author: Daniel-Constantin Mierla <miconda at gmail.com>
Committer: Daniel-Constantin Mierla <miconda at gmail.com>
Date: 2019-10-02T08:32:21+02:00

app_perl: first destroy old interpreter before creating the new one

- on interpreter reset, the new one may inherit globals from the old
one, if that is not yet destroyed

---

Modified: src/modules/app_perl/app_perl_mod.c

---

Diff:  https://github.com/kamailio/kamailio/commit/58047ba61d0cbceebc8c85590970a573fc396aa5.diff
Patch: https://github.com/kamailio/kamailio/commit/58047ba61d0cbceebc8c85590970a573fc396aa5.patch

---

diff --git a/src/modules/app_perl/app_perl_mod.c b/src/modules/app_perl/app_perl_mod.c
index 942581c6d6..954b354638 100644
--- a/src/modules/app_perl/app_perl_mod.c
+++ b/src/modules/app_perl/app_perl_mod.c
@@ -262,6 +262,8 @@ PerlInterpreter *parser_init(void) {
  *
  */
 int unload_perl(PerlInterpreter *p) {
+	/* clean and reset everything */
+	PL_perl_destruct_level = 1;
 	perl_destruct(p);
 	perl_free(p);
 
@@ -276,26 +278,26 @@ int unload_perl(PerlInterpreter *p) {
  */
 int perl_reload(void)
 {
-
-	PerlInterpreter *new_perl;
-
-	new_perl = parser_init();
-
-	if (new_perl) {
+	if(my_perl) {
 		unload_perl(my_perl);
-		my_perl = new_perl;
+	}
+	my_perl = parser_init();
+
 #ifdef PERL_EXIT_DESTRUCT_END
-		PL_exit_flags |= PERL_EXIT_DESTRUCT_END;
+	PL_exit_flags |= PERL_EXIT_DESTRUCT_END;
 #else
 #warning Perl 5.8.x should be used. Please upgrade.
 #warning This binary will be unsupported.
-		PL_exit_flags |= PERL_EXIT_EXPECTED;
+	PL_exit_flags |= PERL_EXIT_EXPECTED;
 #endif
+
+	if(my_perl) {
+		LM_DBG("new perl interpreter initialized\n");
 		return 0;
 	} else {
-		return -1;
+		LM_CRIT("failed to initialize a new perl interpreter - exiting\n");
+		exit(-1);
 	}
-
 }
 
 




More information about the sr-dev mailing list