segmentation fault in socket()

Madsen, Mark Mark.Madsen@divine.com
Wed Dec 11 12:24:00 GMT 2002


This is another problem that I encountered while looking into the
segment fault in select() (see thread: crash in select).

The following code will run until it generates a segmentation fault
somewhere in the call to socket(). The final few lines of the resulting
output are after the code sample.

It's interesting to note that there are errors resulting from cmalloc
returning NULL, but a valid socket descriptor is still returned.

This was run on 1.3.17 on W2K Pro.

Sample below:
----------------------------------------------------
#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <cygwin/in.h>


int main()
{
    int sd;

    while(1)
    {
        printf("Attempting to create next socket.\n");
        if ( ( sd = socket( PF_INET, SOCK_STREAM, 0 ) ) <= 0 )
        {
            printf("Can not get socket!\n");
        }
        else
        {
           printf("Opened socket: %d\n",sd);
        }
// Adding a delay here didn't change the results.
    }
    return 0;
}

Output:
-------
.
.
.
Attempting to create next socket.
Opened socket: 2611
Attempting to create next socket.
Opened socket: 2612
Attempting to create next socket.
      6 [main] test2 7012 cmalloc: cmalloc returned NULL
Opened socket: 2613
Attempting to create next socket.
 101556 [main] test2 7012 cmalloc: cmalloc returned NULL
 101750 [main] test2 7012 cmalloc: cmalloc returned NULL Segmentation
fault (core dumped)

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Bug reporting:         http://cygwin.com/bugs.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/



More information about the Cygwin mailing list