Skip to content

Commit

Permalink
ZXProperly deallocate memory
Browse files Browse the repository at this point in the history
  • Loading branch information
OscarTHZhang-msft committed Jan 8, 2025
1 parent e019986 commit 26e9e53
Show file tree
Hide file tree
Showing 2 changed files with 1,456 additions and 385 deletions.
15 changes: 8 additions & 7 deletions crates/libs/core/src/client/health_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
// Licensed under the MIT License (MIT). See License.txt in the repo root for license information.
// ------------------------------------------------------------

use mssf_com::{FabricClient::IFabricHealthClient4, FabricTypes::FABRIC_HEALTH_REPORT};
use mssf_com::FabricClient::IFabricHealthClient4;

use crate::types::HealthReport;
use crate::types::{FabricHealthReportWrapper, HealthReport};

/// Provides functionality to perform health related operations, like report and query health.
/// See C# API [here](https://docs.microsoft.com/en-us/dotnet/api/system.fabric.fabricclient.healthclient?view=azure-dotnet).
Expand All @@ -28,10 +28,11 @@ impl HealthClient {
/// When a cluster is secured, the health client needs administrator permission to be able to send the reports.
/// Read more about [connecting to a cluster using the FabricClient APIs](https://learn.microsoft.com/en-us/azure/service-fabric/service-fabric-connect-to-secure-cluster).
/// For more information about health reporting, see [Service Fabric health monitoring](https://learn.microsoft.com/en-us/azure/service-fabric/service-fabric-health-introduction).
pub fn report_health(&self, health_report: HealthReport) -> windows_core::Result<()> {
unsafe {
self.com
.ReportHealth(&FABRIC_HEALTH_REPORT::from(&health_report))
}
pub fn report_health(&self, health_report: &HealthReport) -> windows_core::Result<()> {
// The following call will construct a FabricHealthReportWrapper from the HealthReport.
// It does a few heap memory allocations, but it is necessary to pass the health_report to the COM API.
// The memory allocations are then freed by the FabricHealthReportWrapper when it goes out of scope.
let health_report_wrapper = FabricHealthReportWrapper::from(health_report);
unsafe { self.com.ReportHealth(&health_report_wrapper.inner.unwrap()) }
}
}
Loading

0 comments on commit 26e9e53

Please sign in to comment.