Skip to content

Commit

Permalink
moved a memory alloc until its needed
Browse files Browse the repository at this point in the history
  • Loading branch information
jaredmales committed Dec 20, 2023
1 parent f57c2bb commit 079a26e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
3 changes: 0 additions & 3 deletions gui/scripts/dmdisp.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,12 @@ shift #removes the name from args

case ${DMNAME} in
woofer )
dmctrl=dmwoofer
dmindex=00
;;
tweeter )
dmctrl=dmtweeter
dmindex=01
;;
ncpc )
dmctrl=dmncpc
dmindex=02
;;
* )
Expand Down
20 changes: 18 additions & 2 deletions utils/logsurgeon/logsurgeon.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,13 @@ int logsurgeon::execute()


char * buff = new char[fsz];
char * gbuff = new char[fsz];

ssize_t nrd = fread(buff, 1, fsz, fin);
if(nrd != fsz)
{
std::cerr << __FILE__ << " " << __LINE__ << " did not read complete file.\n";
fclose(fin);
delete[] buff;
delete[] gbuff;

return -1;
}
Expand All @@ -107,6 +106,8 @@ int logsurgeon::execute()
ssize_t badSt = 0;
ssize_t kpt = sizeof(logPrioT);

char * gbuff = new char[fsz];

//Now check each byte to see if it is a potential start of a valid log
while(kpt < fsz)
{
Expand Down Expand Up @@ -187,6 +188,8 @@ int logsurgeon::execute()
else if (m_checkOnly)
{
std::cerr << "Check-only mode set, exiting with error status to indicate failed verification\n";
delete[] buff;
delete[] gbuff;
return EXIT_FAILURE;
}
else
Expand All @@ -200,6 +203,8 @@ int logsurgeon::execute()
{
std::cerr << "Error opening corrupted file for writing (" __FILE__ << " " << __LINE__ << ")\n";
std::cerr << "No further action taken\n";
delete[] buff;
delete[] gbuff;
return EXIT_FAILURE;
}

Expand All @@ -211,13 +216,17 @@ int logsurgeon::execute()
{
std::cerr << "Error writing backup corrupted file (" __FILE__ << " " << __LINE__ << ")\n";
std::cerr << "No further action taken\n";
delete[] buff;
delete[] gbuff;
return EXIT_FAILURE;
}

if(fcst != 0)
{
std::cerr << "Error closing backup corrupted file (" __FILE__ << " " << __LINE__ << ")\n";
std::cerr << "No further action taken\n";
delete[] buff;
delete[] gbuff;
return EXIT_FAILURE;
}

Expand All @@ -229,6 +238,9 @@ int logsurgeon::execute()
{
std::cerr << "Error opening existing file for writing (" __FILE__ << " " << __LINE__ << ")\n";
std::cerr << "No further action taken\n";

delete[] buff;
delete[] gbuff;
return EXIT_FAILURE;
}

Expand All @@ -239,12 +251,16 @@ int logsurgeon::execute()
if(fwr != gcurr)
{
std::cerr << "Error writing corrected file (" __FILE__ << " " << __LINE__ << ")\n";
delete[] buff;
delete[] gbuff;
return EXIT_FAILURE;
}

if(fcst != 0)
{
std::cerr << "Error closing corrected file (" __FILE__ << " " << __LINE__ << ")\n";
delete[] buff;
delete[] gbuff;
return EXIT_FAILURE;
}

Expand Down

0 comments on commit 079a26e

Please sign in to comment.