Commit 87a83787 authored by Brickner_cp's avatar Brickner_cp

Fix double FILE closing.

parent b5224c38
...@@ -17,12 +17,6 @@ void OfflinePacketCommunicator::Transmit(PacketSendBuffer^, bool) ...@@ -17,12 +17,6 @@ void OfflinePacketCommunicator::Transmit(PacketSendBuffer^, bool)
throw gcnew InvalidOperationException("Can't transmit queue to an offline device"); throw gcnew InvalidOperationException("Can't transmit queue to an offline device");
} }
OfflinePacketCommunicator::~OfflinePacketCommunicator()
{
if (_file != NULL)
CloseFile(_file);
}
OfflinePacketCommunicator::OfflinePacketCommunicator(String^ filename) OfflinePacketCommunicator::OfflinePacketCommunicator(String^ filename)
: PacketCommunicator(OpenFile(filename), nullptr) : PacketCommunicator(OpenFile(filename), nullptr)
{ {
...@@ -41,19 +35,9 @@ pcap_t* OfflinePacketCommunicator::OpenFile(String^ fileName) ...@@ -41,19 +35,9 @@ pcap_t* OfflinePacketCommunicator::OpenFile(String^ fileName)
pcap_t *pcapDescriptor = pcap_fopen_offline(file, errorBuffer); pcap_t *pcapDescriptor = pcap_fopen_offline(file, errorBuffer);
if (pcapDescriptor == NULL) if (pcapDescriptor == NULL)
{ {
CloseFile(file); fclose(file);
throw gcnew InvalidOperationException(String::Format(CultureInfo::InvariantCulture, "Failed opening file {0}. Error: {1}", fileName, gcnew String(errorBuffer))); throw gcnew InvalidOperationException(String::Format(CultureInfo::InvariantCulture, "Failed opening file {0}. Error: {1}", fileName, gcnew String(errorBuffer)));
} }
_file = file;
return pcapDescriptor; return pcapDescriptor;
} }
// static
void OfflinePacketCommunicator::CloseFile(FILE* file)
{
int result = fclose(file);
if (result != 0)
throw gcnew InvalidOperationException("Failed closing file.");
}
\ No newline at end of file
...@@ -24,16 +24,10 @@ namespace PcapDotNet { namespace Core ...@@ -24,16 +24,10 @@ namespace PcapDotNet { namespace Core
/// <exception cref="System::InvalidOperationException">Thrown always.</exception> /// <exception cref="System::InvalidOperationException">Thrown always.</exception>
virtual void Transmit(PacketSendBuffer^ sendBuffer, bool isSync) override; virtual void Transmit(PacketSendBuffer^ sendBuffer, bool isSync) override;
~OfflinePacketCommunicator();
internal: internal:
OfflinePacketCommunicator(System::String^ fileName); OfflinePacketCommunicator(System::String^ fileName);
private: private:
pcap_t* OpenFile(System::String^ filename); pcap_t* OpenFile(System::String^ filename);
static void CloseFile(FILE* file);
FILE* _file;
}; };
}} }}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment