mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-06-23 10:07:59 +02:00
Dev/server malloc check (#1023)
* usleep in communication to actually relay the err message of memory allocation to the client (weird but test for now), function in server to handle memory allcoation issues (updates mess, ret and sendsit to the client and returns prior from function implementatin, setting fnum in client for the speicific functions that send to detector each argument separtely, they need to remember the fnum else they throw with the incorrect fnum * server: every malloc must check if it succeeded, rearranging so that the free is clear as well (only in funcs so far) * fixed malloc checks in other places other than funcs.c
This commit is contained in:
@ -51,12 +51,12 @@ int dataBytes = 0;
|
||||
int analogDataBytes = 0;
|
||||
int digitalDataBytes = 0;
|
||||
int transceiverDataBytes = 0;
|
||||
char *analogData = 0;
|
||||
char *digitalData = 0;
|
||||
char *transceiverData = 0;
|
||||
char volatile *analogDataPtr = 0;
|
||||
char volatile *digitalDataPtr = 0;
|
||||
char volatile *transceiverDataPtr = 0;
|
||||
char *analogData = NULL;
|
||||
char *digitalData = NULL;
|
||||
char *transceiverData = NULL;
|
||||
char volatile *analogDataPtr = NULL;
|
||||
char volatile *digitalDataPtr = NULL;
|
||||
char volatile *transceiverDataPtr = NULL;
|
||||
char udpPacketData[UDP_PACKET_DATA_BYTES + sizeof(sls_detector_header)];
|
||||
uint32_t adcEnableMask_1g = BIT32_MSK;
|
||||
// 10g readout
|
||||
@ -475,21 +475,15 @@ void setupDetector() {
|
||||
analogDataBytes = 0;
|
||||
digitalDataBytes = 0;
|
||||
transceiverDataBytes = 0;
|
||||
if (analogData) {
|
||||
free(analogData);
|
||||
analogData = 0;
|
||||
}
|
||||
if (digitalData) {
|
||||
free(digitalData);
|
||||
digitalData = 0;
|
||||
}
|
||||
if (transceiverData) {
|
||||
free(transceiverData);
|
||||
transceiverData = 0;
|
||||
}
|
||||
analogDataPtr = 0;
|
||||
digitalDataPtr = 0;
|
||||
transceiverData = 0;
|
||||
free(analogData);
|
||||
analogData = NULL;
|
||||
free(digitalData);
|
||||
digitalData = NULL;
|
||||
free(transceiverData);
|
||||
transceiverData = NULL;
|
||||
analogDataPtr = NULL;
|
||||
digitalDataPtr = NULL;
|
||||
transceiverData = NULL;
|
||||
{
|
||||
for (int i = 0; i < NUM_CLOCKS; ++i) {
|
||||
clkPhase[i] = 0;
|
||||
@ -640,22 +634,15 @@ int updateDatabytesandAllocateRAM() {
|
||||
return FAIL;
|
||||
}
|
||||
// clear RAM
|
||||
if (analogData) {
|
||||
free(analogData);
|
||||
analogData = 0;
|
||||
}
|
||||
if (digitalData) {
|
||||
free(digitalData);
|
||||
digitalData = 0;
|
||||
}
|
||||
if (transceiverData) {
|
||||
free(transceiverData);
|
||||
transceiverData = 0;
|
||||
}
|
||||
free(analogData);
|
||||
analogData = NULL;
|
||||
free(digitalData);
|
||||
digitalData = NULL;
|
||||
free(transceiverData);
|
||||
transceiverData = NULL;
|
||||
// allocate RAM
|
||||
if (analogDataBytes) {
|
||||
analogData = malloc(analogDataBytes);
|
||||
// cannot malloc
|
||||
if (analogData == NULL) {
|
||||
LOG(logERROR, ("Can not allocate analog data RAM for even 1 frame. "
|
||||
"Probable cause: Memory Leak.\n"));
|
||||
@ -665,7 +652,6 @@ int updateDatabytesandAllocateRAM() {
|
||||
}
|
||||
if (digitalDataBytes) {
|
||||
digitalData = malloc(digitalDataBytes);
|
||||
// cannot malloc
|
||||
if (digitalData == NULL) {
|
||||
LOG(logERROR,
|
||||
("Can not allocate digital data RAM for even 1 frame. "
|
||||
@ -677,7 +663,6 @@ int updateDatabytesandAllocateRAM() {
|
||||
}
|
||||
if (transceiverDataBytes) {
|
||||
transceiverData = malloc(transceiverDataBytes);
|
||||
// cannot malloc
|
||||
if (transceiverData == NULL) {
|
||||
LOG(logERROR,
|
||||
("Can not allocate transceiver data RAM for even 1 frame. "
|
||||
|
Reference in New Issue
Block a user