Skip to content

Commit

Permalink
Free regName in SimProc::parseRegister or Register::~Register
Browse files Browse the repository at this point in the history
Signed-off-by: Xiang Xiao <[email protected]>
  • Loading branch information
xiaoxiang781216 committed Jan 3, 2022
1 parent eb59a03 commit 45ef14c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/Register.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
// $Id$


#include <cstdlib>
#include <iostream>

#include "RspProxyMain.h"
Expand All @@ -45,12 +46,20 @@ using std::hex;
//-----------------------------------------------------------------------------
Register::Register ()
{
name = "Unset";
name = NULL;
size = -1;
value = 0;

} // Register ()

Register::~Register ()
{
if (name)
{
free (const_cast<char *>(name));
}
} // ~Register ()


//-----------------------------------------------------------------------------
//! Set the state fields of the register
Expand Down
1 change: 1 addition & 0 deletions src/Register.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class Register

// Constructor
Register ();
~Register ();

// Various accessor functions
void set (const char *_name,
Expand Down
6 changes: 6 additions & 0 deletions src/SimProc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -809,6 +809,7 @@ SimProc::parseRegister (int regNum)
// Error recovery time. If we get a failure between braces, we just scan
// to the end brace and return.
parseError ("comma missing after name. Skipping register specification");
free (regName);
skipBrace ();
return;
}
Expand All @@ -824,6 +825,7 @@ SimProc::parseRegister (int regNum)
// Error recovery time. If we get a failure between braces, we just scan
// to the end brace and return.
parseError ("Register size missing. Skipping register specification");
free (regName);
skipBrace ();
return;
}
Expand All @@ -838,6 +840,7 @@ SimProc::parseRegister (int regNum)
// Error recovery time. If we get a failure between braces, we just scan
// to the end brace and return.
parseError ("comma missing after size. Skipping register specification");
free (regName);
skipBrace ();
return;
}
Expand All @@ -853,6 +856,7 @@ SimProc::parseRegister (int regNum)
// Error recovery time. If we get a failure between braces, we just scan
// to the end brace and return.
parseError ("Register value missing. Skipping register specification");
free (regName);
skipBrace ();
return;
}
Expand All @@ -874,6 +878,7 @@ SimProc::parseRegister (int regNum)
scan (); // Skip unwanted symbol
}

free (regName);
return;
}

Expand All @@ -885,6 +890,7 @@ SimProc::parseRegister (int regNum)
else
{
parseError ("Too many registers specified: %d", regNum);
free (regName);
}
} // parseRegister ()

Expand Down

0 comments on commit 45ef14c

Please sign in to comment.