Skip to content

Commit c00b2af

Browse files
jaeyoon-choiCQ Bot
authored andcommitted
[ufs] Fix a bug in FakeDmaHandler
This CL fixes a bug that leaks VMO handles in FakeDmaHandler. Change-Id: I709fbadef99f6435f832f587b8f5c0f2159a981c Reviewed-on: https://fuchsia-review.googlesource.com/c/fuchsia/+/1158893 Reviewed-by: HanBin Yoon <[email protected]> Commit-Queue: Jaeyoon Choi <[email protected]> Reviewed-by: Christopher Anderson <[email protected]>
1 parent 81062d5 commit c00b2af

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/devices/block/drivers/ufs/test/mock-device/fake-dma-handler.cc

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44

55
#include "fake-dma-handler.h"
66

7+
#include <lib/fit/defer.h>
78
#include <lib/zx/vmar.h>
9+
810
namespace ufs {
911
namespace ufs_mock_device {
1012

@@ -40,7 +42,15 @@ zx::result<zx_vaddr_t> FakeDmaHandler::PhysToVirt(zx_paddr_t paddr) {
4042
return zx::error(status);
4143
}
4244

43-
for (uint32_t vmo_info_index = 0; vmo_info_index < vmo_info_num; ++vmo_info_index) {
45+
uint32_t vmo_info_index;
46+
auto defer = fit::defer([&]() {
47+
// Close all remaining handles
48+
for (++vmo_info_index; vmo_info_index < vmo_info_num; ++vmo_info_index) {
49+
zx_handle_close(vmo_infos[vmo_info_index].vmo);
50+
}
51+
});
52+
53+
for (vmo_info_index = 0; vmo_info_index < vmo_info_num; ++vmo_info_index) {
4454
auto vmo = zx::vmo(vmo_infos[vmo_info_index].vmo);
4555
size_t num_paddrs;
4656
std::vector<zx_paddr_t> paddrs(kFakeBtiAddrsCount);
@@ -65,6 +75,8 @@ zx::result<zx_vaddr_t> FakeDmaHandler::PhysToVirt(zx_paddr_t paddr) {
6575
}
6676
}
6777
}
78+
79+
defer.cancel();
6880
return zx::error(ZX_ERR_NOT_FOUND);
6981
}
7082

0 commit comments

Comments
 (0)