delphizmq
delphizmq copied to clipboard
Non-ZeroMQ exception in TZMQContext.socket( )
An access violation occurs when attempting to get a new socket from a context using TZMQContext.socket
. This is resulting from attempting to call fContext.RemoveSocket( Self )
during the TZMQSocket destructor. In the TZMQContext.socket() call, fContext is set after the exception occurs:
function TZMQContext.Socket( stype: TZMQSocketType ): TZMQSocket;
begin
EnterCriticalSection( cs );
try
result := TZMQSocket.Create;
result.fSocket := zmq_socket( ContextPtr, Byte( stype ) );
if result.fSocket = nil then
begin
result.Free;
result := nil;
raise EZMQException.Create;
end;
result.fContext := self;
fSockets.Add( result );
finally
LeaveCriticalSection( cs );
end;
end;
fContext is not assigned when attempting to remove the socket in the destructor. I suggest adding a check for fContext <> nil
in the TZMQSocket.destroy
method.