Some calls to PerlMemShared_alloc() aren't checking the return value.
Nicholas Clark [Fri, 16 Jul 2004 08:53:28 +0000 (08:53 +0000)]
Bug spotted by Nigel Sandever

p4raw-id: //depot/perl@23121

ext/threads/threads.xs
util.c

index 4148fb0..00ef0aa 100755 (executable)
@@ -389,6 +389,12 @@ Perl_ithread_create(pTHX_ SV *obj, char* classname, SV* init_function, SV* param
 
        MUTEX_LOCK(&create_destruct_mutex);
        thread = PerlMemShared_malloc(sizeof(ithread));
+       if (!thread) {  
+           MUTEX_UNLOCK(&create_destruct_mutex);
+           PerlLIO_write(PerlIO_fileno(Perl_error_log),
+                         PL_no_mem, strlen(PL_no_mem));
+           my_exit(1);
+       }
        Zero(thread,1,ithread);
        thread->next = threads;
        thread->prev = threads->prev;
@@ -755,6 +761,11 @@ BOOT:
        MUTEX_LOCK(&create_destruct_mutex);
        PL_threadhook = &Perl_ithread_hook;
        thread  = PerlMemShared_malloc(sizeof(ithread));
+       if (!thread) {
+           PerlLIO_write(PerlIO_fileno(Perl_error_log),
+                         PL_no_mem, strlen(PL_no_mem));
+           my_exit(1);
+       }
        Zero(thread,1,ithread);
        PL_perl_destruct_level = 2;
        MUTEX_INIT(&thread->mutex);
diff --git a/util.c b/util.c
index 1892fec..030c706 100644 (file)
--- a/util.c
+++ b/util.c
@@ -803,6 +803,11 @@ Perl_savesharedpv(pTHX_ const char *pv)
     register char *newaddr = Nullch;
     if (pv) {
        newaddr = (char*)PerlMemShared_malloc(strlen(pv)+1);
+       if (!newaddr) {
+           PerlLIO_write(PerlIO_fileno(Perl_error_log),
+                         PL_no_mem, strlen(PL_no_mem));
+           my_exit(1);
+       }
        (void)strcpy(newaddr,pv);
     }
     return newaddr;