delphizmq icon indicating copy to clipboard operation
delphizmq copied to clipboard

Non-ZeroMQ exception in TZMQContext.socket( )

Open rpkwv8 opened this issue 8 years ago • 0 comments

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.

rpkwv8 avatar Aug 01 '16 20:08 rpkwv8