Commit 87cd0f61 authored by jan.koester's avatar jan.koester
Browse files

fixed memleak

parent 8c60868e
Loading
Loading
Loading
Loading
+6 −8
Changes for src/event/iocp.cpp: 6 added lines, 8 removed lines.
Original line number Diff line number Diff line
@@ -62,7 +62,7 @@ namespace netplus {

	class client {
	public:
		client(eventapi *eapi) : api(eapi), State(IO_READ_STATE) {
		client(eventapi *eapi) : api(eapi), State(IO_READ_STATE), RecvBuf(BLOCKSIZE) {
			api->CreateConnection(CurCon);
		}

@@ -73,6 +73,7 @@ namespace netplus {
		eventapi                 *api;
		std::unique_ptr<con>      CurCon;
		std::mutex				  cltmtx;
		buffer					  RecvBuf;
	};

	class poll {
@@ -114,9 +115,8 @@ namespace netplus {

			g_eventapi->ConnectEvent(*pClientContext->CurCon, tid, args);

			buffer buf(nullptr, BLOCKSIZE);
			size_t ret=pClientContext->CurCon->csock->recvData(buf, 0);		}

			size_t ret = pClientContext->CurCon->csock->recvData(pClientContext->RecvBuf, 0);
		}
	private:
		HANDLE           g_iocp;
		socket          *g_serversocket;
@@ -258,8 +258,7 @@ namespace netplus {
						}
						else {
							// Stay in read state and initiate another async read
							buffer buf(nullptr,BLOCKSIZE);
							curCon->csock->recvData(buf);
							curCon->csock->recvData(pClientContext->RecvBuf);
						}
					}break;
					case IO_WRITE_STATE: {
@@ -276,8 +275,7 @@ namespace netplus {
						else {
							// All data sent, switch to read state and initiate a new read
							pClientContext->State = IO_READ_STATE;
							buffer buf(nullptr, BLOCKSIZE);
							curCon->csock->recvData(buf);
							curCon->csock->recvData(pClientContext->RecvBuf);
						}
					}break;
					default: {
−2
Changes for src/windows/socket.cpp: 0 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -72,8 +72,6 @@ netplus::socket::~socket(){
    }
    --_InitCount;

	delete[] _wsaBuf.buf;

    free((void*)_SocketInfo);
}

+8 −12
Changes for src/windows/tcp.cpp: 8 added lines, 12 removed lines.
Original line number Diff line number Diff line
@@ -228,17 +228,19 @@ size_t netplus::tcp::sendData(buffer &data,int flags){

size_t netplus::tcp::recvData(buffer &data,int flags){
    NetException exception;
    DWORD dwBytes = 0;

    memset(&_Overlapped, 0, sizeof(WSAOVERLAPPED));

    if (_wsaBuf.buf)
        delete[] _wsaBuf.buf;
    if (data.ptr) {
        exception[NetException::Error] << "Socket recvdata error buffer with const ptr not supported!";
        throw exception;
    }

    _wsaBuf.buf = new char[data.size];
    memset(&_Overlapped, 0, sizeof(WSAOVERLAPPED));

    _wsaBuf.buf = data.data.buf;
    _wsaBuf.len = static_cast<ULONG>(data.size);

    DWORD dwBytes = 0;

    int rval = ::WSARecv(_Socket, &_wsaBuf, 1, &dwBytes, (LPDWORD)&flags, &_Overlapped, nullptr);

    if (rval == SOCKET_ERROR) {
@@ -256,12 +258,6 @@ size_t netplus::tcp::recvData(buffer &data,int flags){
        }
    }

    if (data.ptr) {
		data.data.ptr = _wsaBuf.buf;
    }else{
        std::copy(_wsaBuf.buf, _wsaBuf.buf + dwBytes, data.data.buf);
    }

    return (size_t)dwBytes;
}