]> git.sur5r.net Git - openldap/blobdiff - libraries/libldap_r/thr_lwp.c
Clarify error string, add comment
[openldap] / libraries / libldap_r / thr_lwp.c
index f9bc0b415f7dab16df43d3d9afdbeb0d9206ffd3..3c1dff33890ee2700612f7547fc325e9f779bccd 100644 (file)
@@ -1,3 +1,4 @@
+/* $OpenLDAP$ */
 /*
  * Copyright 1998,1999 The OpenLDAP Foundation, Redwood City, California, USA
  * All rights reserved.
@@ -16,7 +17,6 @@
  */
 
 #include "portable.h"
-#include "ldap_pvt_thread.h"
 
 #if defined( HAVE_LWP )
 
@@ -33,9 +33,9 @@
 #include <ac/time.h>
 #include <ac/socket.h>
 
-#include "lber.h"
-#include "ldap.h"
-#include "ldap_log.h"
+#include "ldap-int.h"
+
+#include "ldap_pvt_thread.h"
 
 #include <lwp/lwp.h>
 #include <lwp/stackdep.h>
@@ -81,8 +81,14 @@ static stkalign_t * ldap_pvt_thread_get_stack( int *stacknop )
        int     i;
 
        if ( stacks == NULL ) {
-               stacks = (struct stackinfo *) ch_calloc( 1, MAX_THREADS *
+               stacks = (struct stackinfo *) LDAP_CALLOC( 1, MAX_THREADS *
                    sizeof(struct stackinfo) );
+
+               if( stacks == NULL ) {
+                       Debug( LDAP_DEBUG_ANY, "stacks allocation failed",
+                               0, 0, 0 );
+                       return NULL;
+               }
        }
 
        for ( i = 0; i < MAX_THREADS; i++ ) {
@@ -99,9 +105,15 @@ static stkalign_t * ldap_pvt_thread_get_stack( int *stacknop )
        }
 
        if ( stacks[i].stk_stack == NULL ) {
-               stacks[i].stk_stack = (stkalign_t *) malloc(
+               stacks[i].stk_stack = (stkalign_t *) LDAP_MALLOC(
                    (MAX_STACK / sizeof(stkalign_t) + 1 )
                    * sizeof(stkalign_t) );
+
+               if( stacks[i].stk_stack == NULL ) {
+                       Debug( LDAP_DEBUG_ANY, "stack allocation failed",
+                               0, 0, 0 );
+                       return( NULL );
+               }
        }
 
        *stacknop = i;
@@ -120,7 +132,7 @@ ldap_pvt_thread_free_stack( int     stackno )
        stacks[stackno].stk_inuse = 0;
 }
 
-static static void
+static void
 lwp_create_stack( void *(*func)(), void *arg, int stackno )
 {
        (*func)( arg );
@@ -180,7 +192,9 @@ ldap_pvt_thread_sleep(
                }
        }
 
-       nt = (tl_t *) malloc( sizeof( tl_t ));
+       nt = (tl_t *) LDAP_MALLOC( sizeof( tl_t ));
+
+       if( nt == NULL ) return -1;
 
        nt->tl_next = sglob->tsl_list;
        nt->tl_wake = now + interval;