Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix memory error when chv and rv are used as calibration parameters. #46

Merged
merged 2 commits into from
Mar 27, 2024

Conversation

hellkite500
Copy link
Member

Memory errors pop up when using chv as a BMI calibratable parameter. This is due to the time delay histogram not being the correct size when set_value calls calc_time_delay_histogram since chv and rv affect the values of tch in convert_dist_to_histords which in turn determines the number of ordinates in the time_delay_histogram.

This PR checks if the number of ordinates has changed and dynamically reallocates the histogram array.

Additions

  • Add chv and rv to bmi unit test parameter list

Changes

  • topmodel.c reallocate time_delay_histogram pointer when size changes

Testing

  1. Unit tests passing local with address sanitizer enabled using clang compiler.

Checklist

  • PR has an informative and human-readable title
  • Changes are limited to a single goal (no scope creep)
  • Code can be automatically merged (no conflicts)
  • Code follows project standards (link if applicable)
  • Passes all existing automated tests
  • Any change in functionality is tested
  • New functions are documented (with a description, list of inputs, and expected output)
  • Placeholder code is flagged / future todos are captured in comments
  • Project documentation has been updated (including the "Unreleased" section of the CHANGELOG)
  • Reviewers requested with the Reviewers tool ➡️

Testing checklist

Target Environment support

  • Linux
  • MacOS

@PhilMiller
Copy link
Contributor

Does Address Sanitizer happen to catch this with just the unit test change and not the code change? That would be a great source of confidence in the fix (which looks good to me)

@hellkite500
Copy link
Member Author

Yes, adding the parameters to the unit test triggered the sanitizer. The proposed fix tested with no errors.

Copy link
Contributor

@Ben-Choat Ben-Choat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Everything looks good and has solved the issue.

@hellkite500 hellkite500 merged commit 479e3c7 into NOAA-OWP:master Mar 27, 2024
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants