From 13c503b73b4ecc8ce4a6e344f9ac15202985d686 Mon Sep 17 00:00:00 2001
From: liuxiaolong <liuxiaolong@aiotlink.com>
Date: 星期二, 20 七月 2021 19:48:58 +0800
Subject: [PATCH] fix memory leak
---
utest/simple_tests.cpp | 40 ++++++----------------------------------
1 files changed, 6 insertions(+), 34 deletions(-)
diff --git a/utest/simple_tests.cpp b/utest/simple_tests.cpp
index e14a1cd..c7f277c 100644
--- a/utest/simple_tests.cpp
+++ b/utest/simple_tests.cpp
@@ -29,33 +29,19 @@
SharedMemory shm(shm_name, 1024 * 1024 * 10);
auto Avail = [&]() { return shm.get_free_memory(); };
- offset_ptr<const void> p;
- BOOST_CHECK(!p);
- BOOST_CHECK(p.get() == 0);
- p = 0;
- BOOST_CHECK(!p);
- BOOST_CHECK(p.get() == 0);
- const char *str = "basic";
- p = str;
- BOOST_CHECK(p);
- BOOST_CHECK(p.get() == str);
- p = 0;
- BOOST_CHECK(!p);
- BOOST_CHECK(p.get() == 0);
-
auto init_avail = Avail();
auto BasicTest = [&](int tid, int nloop) {
auto Code = [&](int id) {
- typedef ShmObject<s1000> Int;
+ typedef NamedShmObject<s1000> Int;
std::string name = std::to_string(id);
auto a0 = Avail();
- Int i1(shm, name);
+ Int i1(shm, name, eOpenOrCreate);
auto a1 = Avail();
BOOST_CHECK_LT(a1, a0);
printf("s1000 size: %ld\n", a0 - a1);
i1->a[0] = 5;
- Int i2(shm, name);
+ Int i2(shm, name, eOpenOrCreate);
auto a2 = Avail();
BOOST_CHECK_EQUAL(a1, a2);
BOOST_CHECK_EQUAL(i1.data(), i2.data());
@@ -104,29 +90,15 @@
}
}
-BOOST_AUTO_TEST_CASE(TimedWaitTest)
-{
- SharedMemory &shm = TestShm();
- GlobalInit(shm);
- ShmMsgQueue q(shm, 64);
- for (int i = 0; i < 2; ++i) {
- int ms = i * 100;
- printf("Timeout Test %4d: ", ms);
- boost::timer::auto_cpu_timer timer;
- MsgI msg;
- bool r = q.Recv(msg, ms);
- BOOST_CHECK(!r);
- }
-}
-
BOOST_AUTO_TEST_CASE(RefCountTest)
{
SharedMemory &shm = TestShm();
typedef MsgI Msg;
GlobalInit(shm);
- Msg m0(1000);
- BOOST_CHECK(m0.valid());
+ Msg m0(1000, shm);
+ BOOST_CHECK(!m0.valid());
+ m0.Make(100);
BOOST_CHECK_EQUAL(m0.Count(), 1);
Msg m1 = m0;
BOOST_CHECK(m1.valid());
--
Gitblit v1.8.0