diff --git a/spwplugin/SpwTcpPacketServer/spwtcppacketserver.cpp b/spwplugin/SpwTcpPacketServer/spwtcppacketserver.cpp --- a/spwplugin/SpwTcpPacketServer/spwtcppacketserver.cpp +++ b/spwplugin/SpwTcpPacketServer/spwtcppacketserver.cpp @@ -23,6 +23,7 @@ #include "ui_spwtcppacketserver.h" #include #include +#include SpwTcpPacketServer::SpwTcpPacketServer(QWidget *parent) : QWidget(parent), @@ -161,8 +162,15 @@ void SpwTcpPacketServer::sendSPWPacketUs + ( (unsigned char) data[2] ) * 256 + (unsigned char) data[3]; char* SPWpacket = (char*)malloc(size); - memcpy(SPWpacket,data.data()+4,size); // 4 bytes will be added later to the packet - emit sendSPWPacket(SPWpacket,size); + if(SPWpacket!=NULL) + { + memcpy(SPWpacket,data.data()+4,size); // 4 bytes will be added later to the packet + emit sendSPWPacket(SPWpacket,size); + } + else + { + //TODO print some message + } } } @@ -186,10 +194,22 @@ void SpwTcpPacketServer::readReady() onePacketReceived(); if(data[0]==(char)0) // Protocole = 0 => Host to SpaceWire packet transmission { - int size = (data[1]*256*256) + (data[2]*256) + data[3]; + // TODO -> change heap allocation to stack risk of memory leak + // if no slot conected to sendSPWPacket signal or segfault if more + // than one receiver. + int size = ( (unsigned char) data[1] ) * 256 * 256 + + ( (unsigned char) data[2] ) * 256 + + (unsigned char) data[3]; char* SPWpacket = (char*)malloc(size); - memcpy(SPWpacket,data.data()+4,size); // 4 bytes will be added later to the packet - emit sendSPWPacket(SPWpacket,size); + if(SPWpacket!=NULL) + { + memcpy(SPWpacket,data.data()+4,size); // 4 bytes will be added later to the packet + emit sendSPWPacket(SPWpacket,size); + } + else + { + //TODO print some message + } } }while(soc->bytesAvailable()!=0); }