@@ -125,23 +125,26 @@ DUK_LOCAL void duk__refcount_finalize_hobject(duk_hthread *thr, duk_hobject *h)
125125 duk_tval * tv , * tv_end ;
126126 duk_hobject * * funcs , * * funcs_end ;
127127
128- DUK_ASSERT (DUK_HCOMPFUNC_GET_DATA (thr -> heap , f ) != NULL ); /* compiled functions must be created 'atomically' */
129-
130- tv = DUK_HCOMPFUNC_GET_CONSTS_BASE (thr -> heap , f );
131- tv_end = DUK_HCOMPFUNC_GET_CONSTS_END (thr -> heap , f );
132- while (tv < tv_end ) {
133- DUK_TVAL_DECREF_NORZ (thr , tv );
134- tv ++ ;
135- }
128+ if (DUK_HCOMPFUNC_GET_DATA (thr -> heap , f ) != NULL ) {
129+ tv = DUK_HCOMPFUNC_GET_CONSTS_BASE (thr -> heap , f );
130+ tv_end = DUK_HCOMPFUNC_GET_CONSTS_END (thr -> heap , f );
131+ while (tv < tv_end ) {
132+ DUK_TVAL_DECREF_NORZ (thr , tv );
133+ tv ++ ;
134+ }
136135
137- funcs = DUK_HCOMPFUNC_GET_FUNCS_BASE (thr -> heap , f );
138- funcs_end = DUK_HCOMPFUNC_GET_FUNCS_END (thr -> heap , f );
139- while (funcs < funcs_end ) {
140- duk_hobject * h_func ;
141- h_func = * funcs ;
142- DUK_ASSERT (DUK_HEAPHDR_IS_OBJECT ((duk_heaphdr * ) h_func ));
143- DUK_HCOMPFUNC_DECREF_NORZ (thr , (duk_hcompfunc * ) h_func );
144- funcs ++ ;
136+ funcs = DUK_HCOMPFUNC_GET_FUNCS_BASE (thr -> heap , f );
137+ funcs_end = DUK_HCOMPFUNC_GET_FUNCS_END (thr -> heap , f );
138+ while (funcs < funcs_end ) {
139+ duk_hobject * h_func ;
140+ h_func = * funcs ;
141+ DUK_ASSERT (DUK_HEAPHDR_IS_OBJECT ((duk_heaphdr * ) h_func ));
142+ DUK_HCOMPFUNC_DECREF_NORZ (thr , (duk_hcompfunc * ) h_func );
143+ funcs ++ ;
144+ }
145+ } else {
146+ /* May happen in some out-of-memory corner cases. */
147+ DUK_D (DUK_DPRINT ("duk_hcompfunc 'data' is NULL, skipping decref" ));
145148 }
146149
147150 DUK_HEAPHDR_DECREF_ALLOWNULL (thr , (duk_heaphdr * ) DUK_HCOMPFUNC_GET_LEXENV (thr -> heap , f ));
0 commit comments