develooper Front page | perl.perl5.porters | Postings from October 2013

[perl #120314] t/re/fold_grind.t spews tons of "Attempt to free temp prematurely" warnings on DEBUGGING but ultimately passes

Thread Previous | Thread Next
From:
bulk88 via RT
Date:
October 23, 2013 00:39
Subject:
[perl #120314] t/re/fold_grind.t spews tons of "Attempt to free temp prematurely" warnings on DEBUGGING but ultimately passes
Message ID:
rt-3.6.HEAD-26210-1382488750-1542.120314-15-0@perl.org
a call stack, this is an -O1 build, so not all params are correct
______________________________
 	perl519.dll!Perl_sv_clear(interpreter * my_perl=0x003644a4, sv * const
orig_sv=0x008fead4)  Line 6527	C
 	perl519.dll!Perl_sv_free2(interpreter * my_perl=0x003644a4, sv * const
sv=0x008fead4, const unsigned long rc=1)  Line 6714	C
 	perl519.dll!Perl_free_tmps(interpreter * my_perl=0x003644a4)  Line
169 + 0x1a	C
>	perl519.dll!S_parse_body(interpreter * my_perl=0x008f498c, char * *
env=0x00362918, void (interpreter *)* xsinit=0x280ed19d)  Line 2379 + 0xf	C
 	perl519.dll!perl_parse(interpreter * my_perl=0x003644a4, void
(interpreter *)* xsinit=0x280ed19d, int argc=4, char * *
argv=0x00362508, char * * env=0x00362918)  Line 1667	C
 	perl519.dll!RunPerl(int argc=4, char * * argv=0x00362508, char * *
env=0x01362d00)  Line 263 + 0x12	C++
 	perl.exe!main(int argc=4, char * * argv=0x00362508, char * *
env=0x00362d00)  Line 22 + 0x12	C
 	perl.exe!_mainCRTStartup()  + 0xe3	
 	kernel32.dll!_BaseProcessStart@4()  + 0x23	
______________________________________________________
    if (PL_do_undump)
	my_unexec();

    if (isWARN_ONCE) {
	SAVECOPFILE(PL_curcop);
	SAVECOPLINE(PL_curcop);
	gv_check(PL_defstash);
    }

    LEAVE;
    FREETMPS; <<<<<<<<<<<<<<<<<<<<<<< Line 2379 S_parse_body

#ifdef MYMALLOC
    {
	const char *s;
    if ((s=PerlEnv_getenv("PERL_DEBUG_MSTATS")) && atoi(s) >= 2)
	dump_mstats("after compilation:");
    }
#endif

    ENTER;
    PL_restartjmpenv = NULL;
    PL_restartop = 0;
    return NULL;
}

_________________________________________________________
    if (PL_main_root) {
	op_free(PL_main_root);
	PL_main_root = NULL;
    }
    PL_main_start = NULL;
    SvREFCNT_dec(PL_main_cv);
    PL_main_cv = NULL;

    time(&PL_basetime);
    oldscope = PL_scopestack_ix;
    PL_dowarn = G_WARN_OFF;

    JMPENV_PUSH(ret);
    switch (ret) {
    case 0:
	parse_body(env,xsinit); <<<<<<<<<<<<Line 1667 perl_parse
	if (PL_unitcheckav) {
	    call_list(oldscope, PL_unitcheckav);
	}
	if (PL_checkav) {
	    PERL_SET_PHASE(PERL_PHASE_CHECK);
	    call_list(oldscope, PL_checkav);
	}
	ret = 0;
	break;
    case 1:
	STATUS_ALL_FAILURE;
	/* FALL THROUGH */
    case 2:
	/* my_exit() was called */
	while (PL_scopestack_ix > oldscope)
	    LEAVE;
	FREETMPS;
	SET_CURSTASH(PL_defstash);
	if (PL_unitcheckav) {
	    call_list(oldscope, PL_unitcheckav);
	}
	if (PL_checkav) {
	    PERL_SET_PHASE(PERL_PHASE_CHECK);
	    call_list(oldscope, PL_checkav);
	}
	ret = STATUS_EXIT;
	break;
    case 3:
	PerlIO_printf(Perl_error_log, "panic: top_env\n");
	ret = 1;
	break;
    }
    JMPENV_POP;
    return ret;
}
_______________________________________________


A different call stack that tried to do a "Attempt to free temp
prematurely:"

_______________________________________________
>	perl519.dll!Perl_ck_warner_d(interpreter * my_perl=0x003644a4,
unsigned long err=22, const char * pat=0x2811c970, ...)  Line 1726	C
 	perl519.dll!Perl_sv_free2(interpreter * my_perl=0x003644a4, sv * const
sv=0x008ff324, const unsigned long rc=1)  Line 6705	C
 
perl519.dll!Perl__invlist_intersection_maybe_complement_2nd(interpreter
* my_perl=0x003644a4, sv * const a=0x008ff324, sv * const b=0x008ff064,
const char complement_b='', sv * * i=0x0012f2ac)  Line 8231 + 0x18	C
 	perl519.dll!S_get_ANYOF_cp_list_for_ssc(interpreter *
my_perl=0x008ff324, const RExC_state_t * pRExC_state=0x0012f928, const
regnode_charclass_class * const node=0x009072a0)  Line 993 + 0x15	C
 	perl519.dll!S_ssc_and(interpreter * my_perl=0x003644a4, const
RExC_state_t * pRExC_state=0x0012f928, regnode_ssc * ssc=0x0012f644,
const regnode_ssc * and_with=0x009072a0)  Line 1070 + 0xc	C
 	perl519.dll!S_study_chunk(interpreter * my_perl=0x003644a4,
RExC_state_t * pRExC_state=0x0012f928, regnode * * scanp=0x0012f74c, int
* minlenp=0x0012fa10, int * deltap=0x0012f700, regnode *
last=0x009072d8, scan_data_t * data=0x1500ffff, long stopparen=-1,
unsigned char * recursed=0x00000000, regnode_ssc * and_withp=0x00000000,
unsigned long flags=10240, unsigned long depth=1)  Line 4535	C
 	perl519.dll!S_study_chunk(interpreter * my_perl=0x003644a4,
RExC_state_t * pRExC_state=0x0012f928, regnode * * scanp=0x0012fa50, int
* minlenp=0x0012fa10, int * deltap=0x0012f8d0, regnode *
last=0x009072d8, scan_data_t * data=0x00000000, long stopparen=-1,
unsigned char * recursed=0x00000000, regnode_ssc * and_withp=0x00000000,
unsigned long flags=11264, unsigned long depth=0)  Line 4156 + 0x2f	C
 	perl519.dll!Perl_re_op_compile(interpreter * my_perl=0x003644a4, sv *
* const patternp=0x00000800, int pat_count=781185092, op *
expr=0x0090727c, const regexp_engine * eng=0x00907298, p5rx *
old_re=0x00000000, char * is_bare_re=0x008ff2a4, unsigned long
orig_rx_flags=771751940, unsigned long pm_flags=134217732)  Line 6548
+ 0x4e	C
 	perl519.dll!Perl_pmruntime(interpreter * my_perl=0x003644a4, op *
o=0x00907101, op * expr=0x00907100, char isreg='', long floor=0)  Line
4827 + 0x1d	C
 	perl519.dll!Perl_yyparse(interpreter * my_perl=0x00905a4c, int
gramtype=381)  Line 1400	C
 	perl519.dll!S_parse_body(interpreter * my_perl=0x008f498c, char * *
env=0x00362918, void (interpreter *)* xsinit=0x280ed19d)  Line 2354 + 0xd	C
 	perl519.dll!perl_parse(interpreter * my_perl=0x003644a4, void
(interpreter *)* xsinit=0x280ed19d, int argc=4, char * *
argv=0x00362508, char * * env=0x00362918)  Line 1667	C
 	perl519.dll!RunPerl(int argc=4, char * * argv=0x00362508, char * *
env=0x01362d00)  Line 263 + 0x12	C++
 	perl.exe!main(int argc=4, char * * argv=0x00362508, char * *
env=0x00362d00)  Line 22 + 0x12	C
 	perl.exe!_mainCRTStartup()  + 0xe3	
 	kernel32.dll!_BaseProcessStart@4()  + 0x23	
______________________________________________________

_________________________________________________________________

void
Perl__invlist_intersection_maybe_complement_2nd(pTHX_ SV* const a, SV*
const b, const bool complement_b, SV** i)
{
    /* Take the intersection of two inversion lists and point <i> to it.  *i
     * SHOULD BE DEFINED upon input, and if it points to one of the two
lists,
     * the reference count to that list will be decremented if not already a
     * temporary (mortal); otherwise *i will be made correspondingly mortal.
     * The first list, <a>, may be NULL, in which case an empty list is
     * returned.  If <complement_b> is TRUE, the result will be the
     * intersection of <a> and the complement (or inversion) of <b>
instead of
     * <b> directly.
     *
     * The basis for this comes from "Unicode Demystified" Chapter 13 by
     * Richard Gillam, published by Addison-Wesley, and explained at some
     * length there.  The preface says to incorporate its examples into your
     * code at your own risk.  In fact, it had bugs
     *
     * The algorithm is like a merge sort, and is essentially the same
as the
     * union above
     */

    const UV* array_a;		/* a's array */
    const UV* array_b;
    UV len_a;	/* length of a's array */
    UV len_b;

    SV* r;		     /* the resulting intersection */
    UV* array_r;
    UV len_r;

    UV i_a = 0;		    /* current index into a's array */
    UV i_b = 0;
    UV i_r = 0;

    /* running count, as explained in the algorithm source book; items are
     * stopped accumulating and are output when the count changes to/from 2.
     * The count is incremented when we start a range that's in the set, and
     * decremented when we start a range that's not in the set.  So its
range
     * is 0 to 2.  Only when the count is 2 is something in the
intersection.
     */
    UV count = 0;

    PERL_ARGS_ASSERT__INVLIST_INTERSECTION_MAYBE_COMPLEMENT_2ND;
    assert(a != b);

    /* Special case if either one is empty */
    len_a = (a == NULL) ? 0 : _invlist_len(a);
    if ((len_a == 0) || ((len_b = _invlist_len(b)) == 0)) {
        bool make_temp = FALSE;

        if (len_a != 0 && complement_b) {

            /* Here, 'a' is not empty, therefore from the above 'if',
'b' must
             * be empty.  Here, also we are using 'b's complement, which
hence
             * must be every possible code point.  Thus the intersection is
             * simply 'a'. */
            if (*i != a) {
                if (*i == b) {
                    if (! (make_temp = SvTEMP(b))) {
                        SvREFCNT_dec_NN(b);
                    }
                }

                *i = invlist_clone(a);
            }
            /* else *i is already 'a' */

            if (make_temp) {
                sv_2mortal(*i);
            }
            return;
        }

        /* Here, 'a' or 'b' is empty and not using the complement of
'b'.  The
         * intersection must be empty */
	if (*i == a) {
            if (! (make_temp = SvTEMP(a))) {
                SvREFCNT_dec_NN(a);
            }
	}
	else if (*i == b) {
            if (! (make_temp = SvTEMP(b))) {
                SvREFCNT_dec_NN(b); <<<<<<<<<<<<<<<<<<<<<<
Perl__invlist_intersection_maybe_complement_2nd Line 8231
            }
	}
	*i = _new_invlist(0);
        if (make_temp) {
            sv_2mortal(*i);
        }

	return;
    }

_________________________________________________________________

STATIC SV*
S_get_ANYOF_cp_list_for_ssc(pTHX_ const RExC_state_t *pRExC_state,
                                  const regnode_charclass_posixl* const
node)
{
    /* Returns a mortal inversion list defining which code points are
matched
     * by 'node', which is of type ANYOF.  Handles complementing the
result if
     * appropriate.  If some code points aren't knowable at this time, the
     * returned list must, and will, contain every possible code point. */

    SV* invlist = sv_2mortal(_new_invlist(0));
    unsigned int i;
    const U32 n = ARG(node);

    PERL_ARGS_ASSERT_GET_ANYOF_CP_LIST_FOR_SSC;

    /* Look at the data structure created by S_set_ANYOF_arg() */
    if (n != ANYOF_NONBITMAP_EMPTY) {
        SV * const rv = MUTABLE_SV(RExC_rxi->data->data[n]);
        AV * const av = MUTABLE_AV(SvRV(rv));
        SV **const ary = AvARRAY(av);
        assert(RExC_rxi->data->what[n] == 's');

        if (ary[1] && ary[1] != &PL_sv_undef) { /* Has compile-time swash */
            invlist = sv_2mortal(invlist_clone(_get_swash_invlist(ary[1])));
        }
        else if (ary[0] && ary[0] != &PL_sv_undef) {

            /* Here, no compile-time swash, and there are things that
won't be
             * known until runtime -- we have to assume it could be
anything */
            return _add_range_to_invlist(invlist, 0, UV_MAX);
        }
        else {

            /* Here no compile-time swash, and no run-time only data. 
Use the
             * node's inversion list */
            invlist = sv_2mortal(invlist_clone(ary[2]));
        }
    }

    /* An ANYOF node contains a bitmap for the first 256 code points, and an
     * inversion list for the others, but if there are code points that
should
     * match only conditionally on the target string being UTF-8, those are
     * placed in the inversion list, and not the bitmap.  Since there are
     * circumstances under which they could match, they are included in the
     * SSC.  But if the ANYOF node is to be inverted, we have to exclude
them
     * here, so that when we invert below, the end result actually does
include
     * them.  (Think about "\xe0" =~ /[^\xc0]/di;).  We have to do this here
     * before we add the unconditionally matched code points */
    if (ANYOF_FLAGS(node) & ANYOF_INVERT) {
        _invlist_intersection_complement_2nd(invlist,
                                             PL_UpperLatin1,
                                             &invlist); <<<<<<<
S_get_ANYOF_cp_list_for_ssc Line 993
    }

________________________________________________________________
STATIC void
S_ssc_and(pTHX_ const RExC_state_t *pRExC_state, regnode_ssc *ssc,
                const regnode_ssc *and_with)
{
    /* Accumulate into SSC 'ssc' its 'AND' with 'and_with', which is either
     * another SSC or a regular ANYOF class.  Can create false positives. */

    SV* anded_cp_list;
    U8  anded_flags;

    PERL_ARGS_ASSERT_SSC_AND;

    assert(OP(ssc) == ANYOF_SYNTHETIC);

    /* 'and_with' is used as-is if it too is an SSC; otherwise have to
extract
     * the code point inversion list and just the relevant flags */
    if (OP(and_with) == ANYOF_SYNTHETIC) {
        anded_cp_list = and_with->invlist;
        anded_flags = ANYOF_FLAGS(and_with);
    }
    else {
        anded_cp_list = get_ANYOF_cp_list_for_ssc(pRExC_state,
                                        (regnode_charclass_posixl*)
and_with); <<<<<<<<<<<<<<<<<S_ssc_and Line 1070
        anded_flags = ANYOF_FLAGS(and_with) & ANYOF_LOCALE_FLAGS;
    }
_________________________________________________________________

I think I'll try making a DEBUG_LEAKING_SCALARS Perl with -Od. IDK when
I'll get around to it.

-- 
bulk88 ~ bulk88 at hotmail.com

---
via perlbug:  queue: perl5 status: new
https://rt.perl.org:443/rt3/Ticket/Display.html?id=120314

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About