On Thu, 20 Jan 2000, Richard Levitte - VMS Whacker wrote:

> rw26> I'm using openssl-0.9.4 on solirs 2.6 on a Sun E3500 (sparc)
> [...]
> 
> Noted.
> 
> rw26> The other problem is with my multithreading. I'm opening a thread
> rw26> for each new accepted socket. When I do this I I call SSL_new, set
> rw26> the fd to my newly accepted connection and call SSL_accept.
> rw26> Here's the code from my server:
> rw26> 
> rw26>   pthread_mutex_lock( &mallfree_mutex );
> rw26>   myev->ssl = SSL_new (ctx);         
> rw26>   CHK_NULL( myev->ssl ); 
> rw26>   SSL_set_fd (myev->ssl, myev->fd);
> rw26>   err = SSL_accept (myev->ssl);
> rw26>   if( err == -1 ) {
> rw26>         close( myev->fd );
> rw26>         SSL_free(myev->ssl);
> rw26>         free( myev );
> rw26>         pthread_mutex_unlock( &mallfree_mutex );
> rw26>         continue;
> rw26>   }      
> rw26>   pthread_mutex_unlock( &mallfree_mutex );
> rw26> 
> rw26> 
> rw26> When I open more than three simultaneous threads, my server does a
> rw26> segmentation fault and crashes. Anybody got any ideas what I need
> rw26> to do?
> 
> Well, the code above doesn't look too bad to me, except I'd like to
> know where myev comes from.  Is it a function-local variable or
> something else?  Same thing goes for err and ctx.  This is clearly a
> multithread-safety issue.
> 
Richard, thanks for the attention. I think you're right that there
is something that isn't thread safe going on.

The variable myev is a struct that I created. Before I call accept() to
aquire a new incoming connection, I will have malloc'd a new struct
pointed to by myev. I have the malloc call protected by a mutex because
I know that malloc is not reentrant. However, if somewhere in the openssl
libraries malloc is also called, perhaps that is when I get this crash. 

Here's the data type what myev points to:

typedef struct nyuev_t {
        int fd;

        SSL *ssl;

        pthread_t thread;       /* thread number for this connection */

        int wantread;           /* set this if we are listening for new 
stuff */
        int wantwrite;          /* set this if when we have filled outbuf
*/

        char outbuf[1024];    /* put the outgoing stuff here */
        char inbuf[1024];     /* get the incoming stuff here */

        int outindex;           /* a pointer used by the socket write
routine */
        int inindex;            /* a pointer used by the socket read
routine */

        struct sockaddr_in peer;/* the remote host's address */
        int peerlen;            /* filled in by accept() */

        struct sockaddr_in myaddr;/* the remote host's address */
        int mylen;              /* filled in by accept() */


        char myip[60];          /* ASCII ip addr of local socket */

        struct nyuev_t * next;

} NYU_EV;


--randy


______________________________________________________________________
OpenSSL Project                                 http://www.openssl.org
User Support Mailing List                    [EMAIL PROTECTED]
Automated List Manager                           [EMAIL PROTECTED]

Reply via email to