WSACleanUp causes an exception

1.7k views Asked by At

My app can switch between Serial and Socket connections, but neither can be open at the same time. So when I try to switch between a Socket to Serial, I delete the Socket connection.

The socket based object uses a private class called UsesWinsock (a big shout out to Len Holgate here as it is basically his code (it is RAII actually but I never applied it to WSA until I saw him do it)). This simply calls WSAStart and and WSACleanUp.

When WSACleanUp is called it tails off into the NTDLL and assembler. @err,hr gives me "The data area passed to a system call is too small" as the HRESULT.

I've tried moving the code around: Moving the class in the order it is inherited causes the destruction sequence to change and actually broke the functions out so they were the last things to be called in the destruct sequence. Neither worked.

I'm pretty sure I've freed everything that is allocated (there's only 1 socket and a couple of events) and I am stuck - this is a fairly important problem for me.

Google is unhelpful returning 4 results of which none solve my problem.

Any suggestions?

2

There are 2 answers

8
Len Holgate On

So, are you using my UsesWinsock class as is? That is, are you saying that it's broken? If so an email directly to me might be a more efficient way of solving the problem ;)

I notice that my code doesn't actually check the return code from WSACleanUp() in the dtor, so, I'm assuming you are checking this, it's SOCKET-ERROR and WSAGetLastError() is reporting ERROR-INSUFFICIENT-BUFFER ?

2
deemok On

I'd be interested to know what you'd find if you used the wt "trace and watch data" command in windows debugger:

Set a break point at the beginning of the WSACleanup:

bp ws2_32!wsacleanup

Once hit, issue the trace command:

wt -oa -oR @$ra

and watch out for calls to ntdll!RtlSetLastWin32Error

You could also post the findings here, it'd interesting to look at them.