Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
dbec5f1f
T
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22017
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
dbec5f1f
编写于
3月 26, 2022
作者:
H
Hongze Cheng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix logical bug with memory leak
上级
0b12117f
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
117 addition
and
46 deletion
+117
-46
source/libs/tdb/src/db/tdbBtree.c
source/libs/tdb/src/db/tdbBtree.c
+6
-6
source/libs/tdb/src/page/tdbPage.c
source/libs/tdb/src/page/tdbPage.c
+5
-1
source/libs/tdb/test/tdbTest.cpp
source/libs/tdb/test/tdbTest.cpp
+106
-39
未找到文件。
source/libs/tdb/src/db/tdbBtree.c
浏览文件 @
dbec5f1f
...
...
@@ -746,6 +746,7 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx) {
pgno
=
TDB_PAGE_PGNO
(
pNews
[
iNew
]);
tdbBtreeEncodeCell
(
pParent
,
cd
.
pKey
,
cd
.
kLen
,
(
void
*
)
&
pgno
,
sizeof
(
SPgno
),
pNewCell
,
&
szNewCell
);
tdbPageInsertCell
(
pParent
,
sIdx
++
,
pNewCell
,
szNewCell
,
0
);
free
(
pNewCell
);
}
// move to next new page
...
...
@@ -795,12 +796,11 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx) {
}
}
// TODO: here has memory leak
// for (int i = 0; i < 3; i++) {
// if (pDivCell[i]) {
// free(pDivCell[i]);
// }
// }
for
(
int
i
=
0
;
i
<
3
;
i
++
)
{
if
(
pDivCell
[
i
])
{
free
(
pDivCell
[
i
]);
}
}
return
0
;
}
...
...
source/libs/tdb/src/page/tdbPage.c
浏览文件 @
dbec5f1f
...
...
@@ -143,7 +143,11 @@ int tdbPageInsertCell(SPage *pPage, int idx, SCell *pCell, int szCell, u8 asOvfl
pPage
->
aiOvfl
[
i
]
=
pPage
->
aiOvfl
[
i
-
1
];
}
pPage
->
apOvfl
[
iOvfl
]
=
pCell
;
// TODO: here has memory leak
pNewCell
=
(
SCell
*
)
malloc
(
szCell
);
memcpy
(
pNewCell
,
pCell
,
szCell
);
pPage
->
apOvfl
[
iOvfl
]
=
pNewCell
;
pPage
->
aiOvfl
[
iOvfl
]
=
idx
;
pPage
->
nOverflow
++
;
iOvfl
++
;
...
...
source/libs/tdb/test/tdbTest.cpp
浏览文件 @
dbec5f1f
...
...
@@ -4,8 +4,112 @@
#include <string>
static
int
tKeyCmpr
(
const
void
*
pKey1
,
int
kLen1
,
const
void
*
pKey2
,
int
kLen2
);
static
int
tDefaultKeyCmpr
(
const
void
*
pKey1
,
int
keyLen1
,
const
void
*
pKey2
,
int
keyLen2
);
typedef
struct
SPoolMem
{
int64_t
size
;
struct
SPoolMem
*
prev
;
struct
SPoolMem
*
next
;
}
SPoolMem
;
static
SPoolMem
*
openPool
()
{
SPoolMem
*
pPool
=
(
SPoolMem
*
)
malloc
(
sizeof
(
*
pPool
));
pPool
->
prev
=
pPool
->
next
=
pPool
;
pPool
->
size
=
0
;
return
pPool
;
}
static
void
closePool
(
SPoolMem
*
pPool
)
{
SPoolMem
*
pMem
;
do
{
pMem
=
pPool
->
next
;
if
(
pMem
==
pPool
)
break
;
pMem
->
next
->
prev
=
pMem
->
prev
;
pMem
->
prev
->
next
=
pMem
->
next
;
pPool
->
size
-=
pMem
->
size
;
free
(
pMem
);
}
while
(
1
);
assert
(
pPool
->
size
==
0
);
free
(
pPool
);
}
static
void
*
poolMalloc
(
void
*
arg
,
int
size
)
{
void
*
ptr
=
NULL
;
SPoolMem
*
pPool
=
(
SPoolMem
*
)
arg
;
SPoolMem
*
pMem
;
pMem
=
(
SPoolMem
*
)
malloc
(
sizeof
(
*
pMem
)
+
size
);
if
(
pMem
==
NULL
)
{
assert
(
0
);
}
pMem
->
size
=
sizeof
(
*
pMem
)
+
size
;
pMem
->
next
=
pPool
->
next
;
pMem
->
prev
=
pPool
;
pPool
->
next
->
prev
=
pMem
;
pPool
->
next
=
pMem
;
pPool
->
size
+=
pMem
->
size
;
ptr
=
(
void
*
)(
&
pMem
[
1
]);
return
ptr
;
}
static
void
poolFree
(
void
*
arg
,
void
*
ptr
)
{
SPoolMem
*
pPool
=
(
SPoolMem
*
)
arg
;
SPoolMem
*
pMem
;
pMem
=
&
(((
SPoolMem
*
)
ptr
)[
-
1
]);
pMem
->
next
->
prev
=
pMem
->
prev
;
pMem
->
prev
->
next
=
pMem
->
next
;
pPool
->
size
-=
pMem
->
size
;
free
(
pMem
);
}
static
int
tKeyCmpr
(
const
void
*
pKey1
,
int
kLen1
,
const
void
*
pKey2
,
int
kLen2
)
{
int
k1
,
k2
;
std
::
string
s1
((
char
*
)
pKey1
+
3
,
kLen1
-
3
);
std
::
string
s2
((
char
*
)
pKey2
+
3
,
kLen2
-
3
);
k1
=
stoi
(
s1
);
k2
=
stoi
(
s2
);
if
(
k1
<
k2
)
{
return
-
1
;
}
else
if
(
k1
>
k2
)
{
return
1
;
}
else
{
return
0
;
}
}
static
int
tDefaultKeyCmpr
(
const
void
*
pKey1
,
int
keyLen1
,
const
void
*
pKey2
,
int
keyLen2
)
{
int
mlen
;
int
cret
;
ASSERT
(
keyLen1
>
0
&&
keyLen2
>
0
&&
pKey1
!=
NULL
&&
pKey2
!=
NULL
);
mlen
=
keyLen1
<
keyLen2
?
keyLen1
:
keyLen2
;
cret
=
memcmp
(
pKey1
,
pKey2
,
mlen
);
if
(
cret
==
0
)
{
if
(
keyLen1
<
keyLen2
)
{
cret
=
-
1
;
}
else
if
(
keyLen1
>
keyLen2
)
{
cret
=
1
;
}
else
{
cret
=
0
;
}
}
return
cret
;
}
TEST
(
tdb_test
,
simple_test
)
{
int
ret
;
...
...
@@ -94,41 +198,4 @@ TEST(tdb_test, simple_test) {
// Close Env
ret
=
tdbEnvClose
(
pEnv
);
GTEST_ASSERT_EQ
(
ret
,
0
);
}
static
int
tKeyCmpr
(
const
void
*
pKey1
,
int
kLen1
,
const
void
*
pKey2
,
int
kLen2
)
{
int
k1
,
k2
;
std
::
string
s1
((
char
*
)
pKey1
+
3
,
kLen1
-
3
);
std
::
string
s2
((
char
*
)
pKey2
+
3
,
kLen2
-
3
);
k1
=
stoi
(
s1
);
k2
=
stoi
(
s2
);
if
(
k1
<
k2
)
{
return
-
1
;
}
else
if
(
k1
>
k2
)
{
return
1
;
}
else
{
return
0
;
}
}
static
int
tDefaultKeyCmpr
(
const
void
*
pKey1
,
int
keyLen1
,
const
void
*
pKey2
,
int
keyLen2
)
{
int
mlen
;
int
cret
;
ASSERT
(
keyLen1
>
0
&&
keyLen2
>
0
&&
pKey1
!=
NULL
&&
pKey2
!=
NULL
);
mlen
=
keyLen1
<
keyLen2
?
keyLen1
:
keyLen2
;
cret
=
memcmp
(
pKey1
,
pKey2
,
mlen
);
if
(
cret
==
0
)
{
if
(
keyLen1
<
keyLen2
)
{
cret
=
-
1
;
}
else
if
(
keyLen1
>
keyLen2
)
{
cret
=
1
;
}
else
{
cret
=
0
;
}
}
return
cret
;
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录