Skip to content

Commit

Permalink
TelematicPlugin: Memory leak (#599)
Browse files Browse the repository at this point in the history
<!-- Thanks for the contribution, this is awesome. -->

# PR Details
## Description
Fix memory leaks issues with several variables created with malloc or
new.
<!--- Describe your changes in detail -->

## Related Issue
#575
<!--- This project only accepts pull requests related to open issues -->
<!--- If suggesting a new feature or change, please discuss it in an
issue first -->
<!--- If fixing a bug, there should be an issue describing it with steps
to reproduce -->
<!--- Please link to the issue here: -->

## Motivation and Context

<!--- Why is this change required? What problem does it solve? -->

## How Has This Been Tested?
Local integration test
<!--- Please describe in detail how you tested your changes. -->
<!--- Include details of your testing environment, and the tests you ran
to -->
<!--- see how your change affects other areas of the code, etc. -->

## Types of changes

<!--- What types of changes does your code introduce? Put an `x` in all
the boxes that apply: -->

- [x] Defect fix (non-breaking change that fixes an issue)
- [ ] New feature (non-breaking change that adds functionality)
- [ ] Breaking change (fix or feature that cause existing functionality
to change)

## Checklist:

<!--- Go over all the following points, and put an `x` in all the boxes
that apply. -->
<!--- If you're unsure about any of these, don't hesitate to ask. We're
here to help! -->

- [ ] I have added any new packages to the sonar-scanner.properties file
- [ ] My change requires a change to the documentation.
- [ ] I have updated the documentation accordingly.
- [x] I have read the **CONTRIBUTING** document.
[V2XHUB Contributing
Guide](https://github.com/usdot-fhwa-OPS/V2X-Hub/blob/develop/Contributing.md)
- [ ] I have added tests to cover my changes.
- [ ] All new and existing tests passed.
  • Loading branch information
dan-du-car authored Apr 16, 2024
1 parent 9fef692 commit 798326e
Showing 1 changed file with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,9 @@ namespace TelematicBridge
{
throw TelematicBridgeException("Failed to convert message with ID (=" + to_string(messageFrame->messageId) + ") to XML ");
}
return string(xml_buffer.buffer);
auto output = string(xml_buffer.buffer);
FREEMEM(xml_buffer.buffer);
return output;
}

/**
Expand Down Expand Up @@ -238,7 +240,10 @@ namespace TelematicBridge
}
else
{
json["payload"] = StringToJson(cJSON_Print(msg->payload));
// Render a cJSON entity to text for transfer/storage. Free the char* when finished.
auto payloadPtr = cJSON_Print(msg->payload);
json["payload"] = StringToJson(payloadPtr);
FREEMEM(payloadPtr);
}
}

Expand Down

0 comments on commit 798326e

Please sign in to comment.