summaryrefslogtreecommitdiff
path: root/gnu/usr.bin/perl/av.c
diff options
context:
space:
mode:
Diffstat (limited to 'gnu/usr.bin/perl/av.c')
-rw-r--r--gnu/usr.bin/perl/av.c12
1 files changed, 11 insertions, 1 deletions
diff --git a/gnu/usr.bin/perl/av.c b/gnu/usr.bin/perl/av.c
index 3219742980d..22cba0fea7a 100644
--- a/gnu/usr.bin/perl/av.c
+++ b/gnu/usr.bin/perl/av.c
@@ -100,6 +100,11 @@ Perl_av_extend(pTHX_ AV *av, I32 key)
}
}
else {
+#ifdef PERL_MALLOC_WRAP
+ static const char oom_array_extend[] =
+ "Out of memory during array extend"; /* Duplicated in pp_hot.c */
+#endif
+
if (AvALLOC(av)) {
#if !defined(STRANGE_MALLOC) && !defined(MYMALLOC)
MEM_SIZE bytes;
@@ -114,6 +119,7 @@ Perl_av_extend(pTHX_ AV *av, I32 key)
#endif
newmax = key + AvMAX(av) / 5;
resize:
+ MEM_WRAP_CHECK_1(newmax+1, SV*, oom_array_extend);
#if defined(STRANGE_MALLOC) || defined(MYMALLOC)
Renew(AvALLOC(av),newmax+1, SV*);
#else
@@ -148,6 +154,7 @@ Perl_av_extend(pTHX_ AV *av, I32 key)
}
else {
newmax = key < 3 ? 3 : key;
+ MEM_WRAP_CHECK_1(newmax+1, SV*, oom_array_extend);
New(2,AvALLOC(av), newmax+1, SV*);
ary = AvALLOC(av) + 1;
tmp = newmax;
@@ -780,7 +787,8 @@ Perl_av_fill(pTHX_ register AV *av, I32 fill)
=for apidoc av_delete
Deletes the element indexed by C<key> from the array. Returns the
-deleted element. C<flags> is currently ignored.
+deleted element. If C<flags> equals C<G_DISCARD>, the element is freed
+and null is returned.
=cut
*/
@@ -838,6 +846,8 @@ Perl_av_delete(pTHX_ AV *av, I32 key, I32 flags)
if (key > AvFILLp(av))
return Nullsv;
else {
+ if (!AvREAL(av) && AvREIFY(av))
+ av_reify(av);
sv = AvARRAY(av)[key];
if (key == AvFILLp(av)) {
AvARRAY(av)[key] = &PL_sv_undef;