# New Ticket Created by NotFound
# Please include the string: [perl #56538]
# in the subject line of all future correspondence about this issue.
# <URL: http://rt.perl.org/rt3/Ticket/Display.html?id=56538 >
The imcc_init function is called from several places, and it allocates
memory without checking if already is initialized, with potential
memory leaking.
However, it's called during interpreter creation. And putting the assertion:
PARROT_ASSERT(IMCC_INFO(interp) == NULL);
confirms that is called several tiems, breaking a lot of tests.
Worse, the function lacks a prototype in an easily available header.
This patch cleans the isuue by dropping all calls from all places
except interpreter creation, and puts the assertion in place to verify
that is not recalled, avoiding memory leaks.
--
Salu2
Index: src/pdb.c
===================================================================
--- src/pdb.c (revisión: 28963)
+++ src/pdb.c (copia de trabajo)
@@ -124,8 +124,6 @@
*/
-extern void imcc_init(Parrot_Interp interp);
-
int
main(int argc, char *argv[])
{
@@ -145,7 +143,6 @@
Parrot_block_GC_mark(interp);
Parrot_block_GC_sweep(interp);
- imcc_init(interp);
do_yylex_init(interp, &yyscanner);
Index: src/debug.c
===================================================================
--- src/debug.c (revisión: 28963)
+++ src/debug.c (copia de trabajo)
@@ -34,7 +34,6 @@
PARROT_API
void
IMCC_warning(PARROT_INTERP, ARGIN(const char *fmt), ...);
-extern void imcc_init(PARROT_INTERP);
/*
* These constants correspond to the debugger commands.
Index: compilers/imcc/parser_util.c
===================================================================
--- compilers/imcc/parser_util.c (revisión: 28963)
+++ compilers/imcc/parser_util.c (copia de trabajo)
@@ -1716,6 +1716,8 @@
void
imcc_init(PARROT_INTERP)
{
+ PARROT_ASSERT(IMCC_INFO(interp) == NULL);
+
IMCC_INFO(interp) = mem_allocate_zeroed_typed(imc_info_t);
/* register PASM and PIR compilers to parrot core */
register_compilers(interp);
Index: t/src/compiler.t
===================================================================
--- t/src/compiler.t (revisión: 28963)
+++ t/src/compiler.t (copia de trabajo)
@@ -35,8 +35,6 @@
#include "parrot/parrot.h"
#include "parrot/embed.h"
-extern void imcc_init(Parrot_Interp interp);
-
static opcode_t *
run(Parrot_Interp interp, int argc, char *argv[])
{
@@ -100,9 +98,6 @@
if (interp == NULL)
return 1;
- /* this registers the PIR compiler */
- imcc_init(interp);
-
/* dummy pf and segment to get things started */
pf = PackFile_new_dummy(interp, "test_code");
@@ -123,12 +118,6 @@
#include "parrot/embed.h"
#include "parrot/extend.h"
-#ifndef __cplusplus
-extern void imcc_init(Parrot_Interp interp);
-#else
-extern "C" void imcc_init(Parrot_Interp interp);
-#endif
-
static opcode_t *
run(Parrot_Interp interp, int argc, char *argv[])
{
@@ -193,8 +182,6 @@
if (interp == NULL)
return 1;
- /* this registers the PIR compiler */
- imcc_init(interp);
/* dummy pf and segment to get things started */
pf = PackFile_new_dummy(interp, "test_code");
@@ -213,12 +200,6 @@
#include "parrot/embed.h"
#include "parrot/extend.h"
-#ifndef __cplusplus
-extern void imcc_init(Parrot_Interp interp);
-#else
-extern "C" void imcc_init(Parrot_Interp interp);
-#endif
-
static void
compile_run(Parrot_Interp interp, const char *src, STRING *type, int argc,
char *argv[])
@@ -293,9 +274,6 @@
if (interp == NULL)
return 1;
- /* this registers the PIR compiler */
- imcc_init(interp);
-
/* dummy pf and segment to get things started */
pf = PackFile_new_dummy(interp, "test_code");
@@ -315,12 +293,6 @@
#include "parrot/embed.h"
#include "parrot/extend.h"
-#ifndef __cplusplus
-extern void imcc_init(Parrot_Interp interp);
-#else
-extern "C" void imcc_init(Parrot_Interp interp);
-#endif
-
static void
compile_run(Parrot_Interp interp, const char *src, STRING *type, int argc,
char *argv[])
@@ -395,9 +367,6 @@
if (interp == NULL)
return 1;
- /* this registers the PIR compiler */
- imcc_init(interp);
-
/* dummy pf and segment to get things started */
pf = PackFile_new_dummy(interp, "test_code");
@@ -417,12 +386,6 @@
#include "parrot/embed.h"
#include "parrot/extend.h"
-#ifndef __cplusplus
-extern void imcc_init(Parrot_Interp interp);
-#else
-extern "C" void imcc_init(Parrot_Interp interp);
-#endif
-
static void
compile_run(Parrot_Interp interp, const char *src, STRING *type, int argc,
char *argv[])
@@ -496,9 +459,6 @@
if (interp == NULL)
return 1;
- /* this registers the PIR compiler */
- imcc_init(interp);
-
/* dummy pf and segment to get things started */
pf = PackFile_new_dummy(interp, "test_code");
@@ -518,12 +478,6 @@
#include "parrot/embed.h"
#include "parrot/extend.h"
-#ifdef __cplusplus
-extern "C" void imcc_init(Parrot_Interp interp);
-#else
-extern void imcc_init(Parrot_Interp interp);
-#endif
-
static void
compile_run(Parrot_Interp interp, const char *src, STRING *type, int argc,
char *argv[])
@@ -596,9 +550,6 @@
if (interp == NULL)
return 1;
- /* this registers the PIR compiler */
- imcc_init(interp);
-
/* dummy pf and segment to get things started */
pf = PackFile_new_dummy(interp, "test_code");