Skip to content

Commit

Permalink
Fix heap memory allocation for domain specific tag
Browse files Browse the repository at this point in the history
Signed-off-by: romanodanilo <[email protected]>
  • Loading branch information
romanodanilo committed Jun 11, 2024
1 parent 3b41141 commit be08f1e
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 15 deletions.
12 changes: 11 additions & 1 deletion include/common/result_format/c_domain_specific_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,14 @@ class cDomainSpecificInfo
* \param inputRoot: xml tree root for the initialization
* \param name: Name of the tag
*/
cDomainSpecificInfo(DOMElement *inputRoot, const std::string &name = "") : m_Root(inputRoot), m_Name(name)
cDomainSpecificInfo(DOMElement *inputRoot, const std::string &name = "") : m_Name(name)
{
// Get the original document's implementation
DOMImplementation *impl = inputRoot->getOwnerDocument()->getImplementation();
// Create a new document to own the cloned element
m_Doc = impl->createDocument();
// Import the element into the new document, effectively cloning it
m_Root = dynamic_cast<DOMElement *>(m_Doc->importNode(inputRoot, true));
}

// Serialize this information
Expand All @@ -44,9 +50,13 @@ class cDomainSpecificInfo
DOMElement *GetRoot() const;
// Returns the name
std::string GetName() const;
DOMDocument *GetDoc() const;

~cDomainSpecificInfo();

protected:
DOMElement *m_Root;
DOMDocument *m_Doc;
std::string m_Name;

private:
Expand Down
4 changes: 3 additions & 1 deletion include/common/result_format/c_issue.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class cIssue : public IResult
*
*/
cIssue(const std::string &description, eIssueLevel infoLvl, const std::string &ruleUID = "",
cLocationsContainer *locationsContainer = nullptr);
cLocationsContainer *locationsContainer = nullptr, cDomainSpecificInfo *domainSpecificInfo = nullptr);

/*
* Creates a new Issue
Expand Down Expand Up @@ -89,6 +89,8 @@ class cIssue : public IResult
// Returns th count of locations
std::size_t GetLocationsCount() const;

size_t GetDomainSpecificCount() const;

// Assigns an issue to a checker
void AssignChecker(cChecker *checkerToAssign);

Expand Down
8 changes: 4 additions & 4 deletions runtime/tests/test_runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def check_node_exists(xml_file: str, node_name: str) -> bool:

def test_runtime_execution():

# start_wd = os.getcwd()
start_wd = os.getcwd()
install_dir = os.path.join("..", "build", "bin")
os.chdir(install_dir)

Expand Down Expand Up @@ -95,12 +95,12 @@ def test_runtime_execution():
node_name = "Issue"
assert check_node_exists(result_file, node_name)

# os.chdir(start_wd)
os.chdir(start_wd)


def test_3steps_config():

# start_wd = os.getcwd()
start_wd = os.getcwd()
install_dir = os.path.join("..", "build", "bin")
os.chdir(install_dir)

Expand Down Expand Up @@ -135,4 +135,4 @@ def test_3steps_config():
result_file = os.path.join("Report.txt")
assert os.path.isfile(result_file)

# os.chdir(start_wd)
os.chdir(start_wd)
21 changes: 18 additions & 3 deletions src/common/src/result_format/c_domain_specific_info.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,24 @@

const XMLCh *cDomainSpecificInfo::TAG_DOMAIN_SPECIFIC_INFO = CONST_XMLCH("DomainSpecificInfo");
const XMLCh *cDomainSpecificInfo::ATTR_NAME = CONST_XMLCH("name");
// Returns the X
// Returns the root
DOMElement *cDomainSpecificInfo::GetRoot() const
{
return m_Root;
}
DOMDocument *cDomainSpecificInfo::GetDoc() const
{
return m_Doc;
}
std::string cDomainSpecificInfo::GetName() const
{
return m_Name;
}

cDomainSpecificInfo::~cDomainSpecificInfo()
{
m_Doc->release();
}

DOMElement *cDomainSpecificInfo::WriteXML(DOMDocument *p_resultDocument)
{
Expand All @@ -42,6 +55,8 @@ DOMElement *cDomainSpecificInfo::WriteXML(DOMDocument *p_resultDocument)
cDomainSpecificInfo *cDomainSpecificInfo::ParseFromXML(DOMNode *pXMLNode, DOMElement *pXMLElement)
{
std::string strName = XMLString::transcode(pXMLElement->getAttribute(ATTR_NAME));
cDomainSpecificInfo *domain_info = new cDomainSpecificInfo(pXMLElement, strName);
return domain_info;

cDomainSpecificInfo *domainInfo = new cDomainSpecificInfo(pXMLElement, strName);
// Return the parsed instance
return domainInfo;
}
25 changes: 20 additions & 5 deletions src/common/src/result_format/c_issue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ const std::map<eIssueLevel, std::string> cIssue::issueLevelToString = {
{eIssueLevel::INFO_LVL, "Info"}, {eIssueLevel::WARNING_LVL, "Warning"}, {eIssueLevel::ERROR_LVL, "Error"}};

cIssue::cIssue(const std::string &description, eIssueLevel infoLvl, const std::string &ruleUID,
cLocationsContainer *locationsContainer)
cLocationsContainer *locationsContainer, cDomainSpecificInfo *domainSpecificInfo)
{
m_Description = description;
m_IssueLevel = infoLvl;
m_RuleUID = ruleUID;
m_Checker = nullptr;

AddLocationsContainer(locationsContainer);
AddDomainSpecificInfo(domainSpecificInfo);
}

cIssue::cIssue(const std::string &description, eIssueLevel infoLvl, std::list<cLocationsContainer *> listLoc)
Expand Down Expand Up @@ -64,8 +64,14 @@ cIssue::~cIssue()
{
delete (*locIt);
}
for (std::list<cDomainSpecificInfo *>::const_iterator domIt = m_DomainSpecificInfo.cbegin();
domIt != m_DomainSpecificInfo.cend(); domIt++)
{
delete (*domIt);
}

m_Locations.clear();
m_DomainSpecificInfo.clear();
}

void cIssue::AddLocationsContainer(cLocationsContainer *locationsContainer)
Expand Down Expand Up @@ -212,11 +218,10 @@ cIssue *cIssue::ParseFromXML(DOMNode *pXMLNode, DOMElement *pXMLElement, cChecke
issue->AddLocationsContainer(
(cLocationsContainer *)cLocationsContainer::ParseFromXML(currentIssueNode, currentIssueElement));
}
// Parse cFileLocation
// Parse cDomainSpecificInfo
if (Equals(currentTagName, XMLString::transcode(cDomainSpecificInfo::TAG_DOMAIN_SPECIFIC_INFO)))
{
issue->AddDomainSpecificInfo(
(cDomainSpecificInfo *)cDomainSpecificInfo::ParseFromXML(currentIssueNode, currentIssueElement));
issue->AddDomainSpecificInfo(cDomainSpecificInfo::ParseFromXML(currentIssueNode, currentIssueElement));
}
}
}
Expand All @@ -239,12 +244,22 @@ size_t cIssue::GetLocationsCount() const
return m_Locations.size();
}

size_t cIssue::GetDomainSpecificCount() const
{
return m_DomainSpecificInfo.size();
}

// Returns all extended informations
std::list<cLocationsContainer *> cIssue::GetLocationsContainer() const
{
return m_Locations;
}

std::list<cDomainSpecificInfo *> cIssue::GetDomainSpecificInfo() const
{
return m_DomainSpecificInfo;
}

eIssueLevel cIssue::GetIssueLevelFromStr(const std::string &issueLevelString)
{
return (eIssueLevel)stoi(issueLevelString);
Expand Down
2 changes: 1 addition & 1 deletion src/common/src/result_format/c_result_container.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ void cResultContainer::AddResultsFromXML(const std::string &strXmlFilePath)
}

delete pDomParser;
XMLPlatformUtils::Terminate();
// XMLPlatformUtils::Terminate();
}
}

Expand Down

0 comments on commit be08f1e

Please sign in to comment.