From fe09f6d062ee598fc5eb6df03d6c26a57a539813 Mon Sep 17 00:00:00 2001 From: Erik Frojdh Date: Wed, 16 Jan 2019 10:29:10 +0100 Subject: [PATCH 1/3] cleaning up slsDetectorCommand --- .../slsDetector/slsDetectorCommand.cpp | 1 + .../slsDetectorClient/sls_detector_client.cpp | 14 ++++---------- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/slsDetectorSoftware/slsDetector/slsDetectorCommand.cpp b/slsDetectorSoftware/slsDetector/slsDetectorCommand.cpp index 009a33528..cff9bbd94 100644 --- a/slsDetectorSoftware/slsDetector/slsDetectorCommand.cpp +++ b/slsDetectorSoftware/slsDetector/slsDetectorCommand.cpp @@ -1,5 +1,6 @@ #include "slsDetectorCommand.h" #include "multiSlsDetector.h" +#include "string_utils.h" #include #include diff --git a/slsDetectorSoftware/slsDetectorClient/sls_detector_client.cpp b/slsDetectorSoftware/slsDetectorClient/sls_detector_client.cpp index d0525f9a6..5c658b594 100644 --- a/slsDetectorSoftware/slsDetectorClient/sls_detector_client.cpp +++ b/slsDetectorSoftware/slsDetectorClient/sls_detector_client.cpp @@ -1,9 +1,7 @@ #include "multiSlsDetectorClient.h" #include "gitInfoLib.h" - -#include -using namespace std; +#include int main(int argc, char *argv[]) @@ -11,7 +9,7 @@ int main(int argc, char *argv[]) for (int i = 1; i < argc; ++i ) { if (!(strcmp (argv[i],"--version")) || !(strcmp (argv[i],"-v"))) { int64_t tempval = GITDATE; - cout << argv[0] << " " << GITBRANCH << " (0x" << hex << tempval << ")" << endl; + std::cout << argv[0] << " " << GITBRANCH << " (0x" << std::hex << tempval << ")" << std::endl; return 0; } } @@ -24,23 +22,19 @@ int main(int argc, char *argv[]) int action=slsDetectorDefs::GET_ACTION; #endif - #ifdef READOUT int action=slsDetectorDefs::READOUT_ACTION; #endif - #ifdef HELP int action=slsDetectorDefs::HELP_ACTION; #endif - multiSlsDetectorClient *cl; if (argc>1) - cl=new multiSlsDetectorClient(argc-1, argv+1, action); + multiSlsDetectorClient(argc-1, argv+1, action); else - cl=new multiSlsDetectorClient(argc-1, argv, action); + multiSlsDetectorClient(argc-1, argv, action); - delete cl; } From 68545f2b26415c3cb5c5642850a762616f9a8a42 Mon Sep 17 00:00:00 2001 From: Erik Frojdh Date: Wed, 16 Jan 2019 10:56:51 +0100 Subject: [PATCH 2/3] removed pointer in multiSlsDetectorClient --- CMakeLists.txt | 8 +++- .../multiSlsDetector/multiSlsDetectorClient.h | 17 +++---- .../slsDetectorClient/sls_detector_client.cpp | 45 ++++++++----------- 3 files changed, 34 insertions(+), 36 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 46c2769ec..308de5a55 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -26,8 +26,12 @@ endif() set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -std=c++11 ") -set (CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -fno-omit-frame-pointer -fsanitize=thread") -set (CMAKE_LINKER_FLAGS_DEBUG "${CMAKE_LINKER_FLAGS_DEBUG} -fno-omit-frame-pointer -fsanitize=thread") +# set (CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -fno-omit-frame-pointer -fsanitize=thread") +# set (CMAKE_LINKER_FLAGS_DEBUG "${CMAKE_LINKER_FLAGS_DEBUG} -fno-omit-frame-pointer -fsanitize=thread") +set (CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -fno-omit-frame-pointer -fsanitize=address") +set (CMAKE_LINKER_FLAGS_DEBUG "${CMAKE_LINKER_FLAGS_DEBUG} -fno-omit-frame-pointer -fsanitize=address") + + find_package(Qt4) find_package(Qwt 6) diff --git a/slsDetectorSoftware/multiSlsDetector/multiSlsDetectorClient.h b/slsDetectorSoftware/multiSlsDetector/multiSlsDetectorClient.h index f36be73df..ed546aa4b 100644 --- a/slsDetectorSoftware/multiSlsDetector/multiSlsDetectorClient.h +++ b/slsDetectorSoftware/multiSlsDetector/multiSlsDetectorClient.h @@ -20,7 +20,7 @@ class multiSlsDetectorClient { public: multiSlsDetectorClient(int argc, char *argv[], int action, multiSlsDetector *myDetector=NULL) { \ std::string answer; \ - multiSlsDetectorCommand *myCmd; \ + // multiSlsDetectorCommand *myCmd; int id = -1, pos = -1, iv = 0; \ bool verify = true, update = true; \ int del = 0; \ @@ -122,18 +122,19 @@ public: std::cout << "position is out of bounds." << std::endl; \ return; \ } \ - // call multi detector command line - myCmd=new multiSlsDetectorCommand(myDetector); \ - try { \ - answer=myCmd->executeLine(argc, argv, action, pos); \ + + try { + // call multi detector command line + multiSlsDetectorCommand myCmd(myDetector); \ + answer=myCmd.executeLine(argc, argv, action, pos); \ } catch (const SlsDetectorPackageExceptions & e) { \ /*std::cout << e.GetMessage() << std::endl; */ \ - delete myCmd; \ + if (del) delete myDetector; \ return; \ } catch (...) { \ std::cout << " caught exception" << std::endl; \ - delete myCmd; \ + \ if (del) delete myDetector; \ return; \ } \ @@ -141,7 +142,7 @@ public: std::cout << argv[0] << " " ; \ } \ std::cout << answer<< std::endl; \ - delete myCmd; \ + \ if (del) delete myDetector; \ }; diff --git a/slsDetectorSoftware/slsDetectorClient/sls_detector_client.cpp b/slsDetectorSoftware/slsDetectorClient/sls_detector_client.cpp index 5c658b594..469803064 100644 --- a/slsDetectorSoftware/slsDetectorClient/sls_detector_client.cpp +++ b/slsDetectorSoftware/slsDetectorClient/sls_detector_client.cpp @@ -1,40 +1,33 @@ -#include "multiSlsDetectorClient.h" #include "gitInfoLib.h" - +#include "multiSlsDetectorClient.h" #include -int main(int argc, char *argv[]) - -{ - for (int i = 1; i < argc; ++i ) { - if (!(strcmp (argv[i],"--version")) || !(strcmp (argv[i],"-v"))) { - int64_t tempval = GITDATE; - std::cout << argv[0] << " " << GITBRANCH << " (0x" << std::hex << tempval << ")" << std::endl; - return 0; - } - } +int main(int argc, char *argv[]) { + for (int i = 1; i < argc; ++i) { + if (!(strcmp(argv[i], "--version")) || !(strcmp(argv[i], "-v"))) { + int64_t tempval = GITDATE; + std::cout << argv[0] << " " << GITBRANCH << " (0x" << std::hex << tempval << ")" << std::endl; + return 0; + } + } #ifdef PUT - int action=slsDetectorDefs::PUT_ACTION; + int action = slsDetectorDefs::PUT_ACTION; #endif - + #ifdef GET - int action=slsDetectorDefs::GET_ACTION; + int action = slsDetectorDefs::GET_ACTION; #endif - + #ifdef READOUT - int action=slsDetectorDefs::READOUT_ACTION; + int action = slsDetectorDefs::READOUT_ACTION; #endif - + #ifdef HELP - int action=slsDetectorDefs::HELP_ACTION; + int action = slsDetectorDefs::HELP_ACTION; #endif - if (argc>1) - multiSlsDetectorClient(argc-1, argv+1, action); - else - multiSlsDetectorClient(argc-1, argv, action); - + if (argc > 1) + argv++; + multiSlsDetectorClient(argc - 1, argv, action); } - - From 901785b8181d90b9432e761d425547c950a0fbac Mon Sep 17 00:00:00 2001 From: Erik Frojdh Date: Wed, 16 Jan 2019 11:51:50 +0100 Subject: [PATCH 3/3] only destroy sem if it was initialized --- slsReceiverSoftware/src/Listener.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/slsReceiverSoftware/src/Listener.cpp b/slsReceiverSoftware/src/Listener.cpp index 069f99d0f..8c229a8a2 100644 --- a/slsReceiverSoftware/src/Listener.cpp +++ b/slsReceiverSoftware/src/Listener.cpp @@ -64,9 +64,12 @@ Listener::Listener(int ind, detectorType dtype, Fifo* f, runStatus* s, Listener::~Listener() { - if (udpSocket) delete udpSocket; - sem_post(&semaphore_socket); - sem_destroy(&semaphore_socket); + if (udpSocket){ + delete udpSocket; + sem_post(&semaphore_socket); + sem_destroy(&semaphore_socket); + } + if (carryOverPacket) delete [] carryOverPacket; if (listeningPacket) delete [] listeningPacket; ThreadObject::DestroyThread();