Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
node-sqlite3
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
俞永鹏
node-sqlite3
Commits
35e5534f
Commit
35e5534f
authored
Aug 14, 2010
by
Orlando Vazquez
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix a memory leak introduced when the files were split up.
Column data (name and type) should only be allocated once.
parent
55f8cfb8
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
28 deletions
+24
-28
statement.cc
src/statement.cc
+20
-20
speedtest-low-parallel.js
tests/old/speedtest-low-parallel.js
+4
-8
No files found.
src/statement.cc
View file @
35e5534f
...
...
@@ -553,10 +553,10 @@ void Statement::FreeColumnData(void) {
for
(
int
i
=
0
;
i
<
column_count_
;
i
++
)
{
switch
(
column_types_
[
i
])
{
case
SQLITE_INTEGER
:
free
(
column_data_
[
i
]);
free
(
(
int
*
)
column_data_
[
i
]);
break
;
case
SQLITE_FLOAT
:
free
(
column_data_
[
i
]);
free
(
(
double
*
)
column_data_
[
i
]);
break
;
}
column_data_
[
i
]
=
NULL
;
...
...
@@ -607,31 +607,31 @@ int Statement::EIO_Step(eio_req *req) {
sto
->
column_data_
=
(
void
**
)
calloc
(
sto
->
column_count_
,
sizeof
(
void
*
));
}
}
for
(
int
i
=
0
;
i
<
sto
->
column_count_
;
i
++
)
{
sto
->
column_types_
[
i
]
=
sqlite3_column_type
(
stmt
,
i
);
for
(
int
i
=
0
;
i
<
sto
->
column_count_
;
i
++
)
{
sto
->
column_types_
[
i
]
=
sqlite3_column_type
(
stmt
,
i
);
// Don't free this!
sto
->
column_names_
[
i
]
=
(
char
*
)
sqlite3_column_name
(
stmt
,
i
);
// Don't free this!
sto
->
column_names_
[
i
]
=
(
char
*
)
sqlite3_column_name
(
stmt
,
i
);
switch
(
sto
->
column_types_
[
i
])
{
case
SQLITE_INTEGER
:
sto
->
column_data_
[
i
]
=
(
int
*
)
malloc
(
sizeof
(
int
));
break
;
switch
(
sto
->
column_types_
[
i
])
{
case
SQLITE_INTEGER
:
sto
->
column_data_
[
i
]
=
(
int
*
)
malloc
(
sizeof
(
int
));
break
;
case
SQLITE_FLOAT
:
sto
->
column_data_
[
i
]
=
(
double
*
)
malloc
(
sizeof
(
double
));
break
;
case
SQLITE_FLOAT
:
sto
->
column_data_
[
i
]
=
(
double
*
)
malloc
(
sizeof
(
double
));
break
;
case
SQLITE_NULL
:
sto
->
column_data_
[
i
]
=
NULL
;
break
;
case
SQLITE_NULL
:
sto
->
column_data_
[
i
]
=
NULL
;
break
;
// no need to allocate memory for strings
// no need to allocate memory for strings
default
:
{
// unsupported type
default
:
{
// unsupported type
}
}
}
}
...
...
tests/old/speedtest-low-parallel.js
View file @
35e5534f
var
sqlite
=
require
(
'
../
sqlite3_bindings'
);
var
sqlite
=
require
(
'sqlite3_bindings'
);
var
sys
=
require
(
'sys'
);
var
assert
=
require
(
'assert'
);
...
...
@@ -21,7 +21,7 @@ function getRows() {
var
d
;
if
(
error
)
throw
error
;
if
(
!
row
)
{
statement
.
finalize
(
function
()
{
});
statement
.
finalize
(
function
()
{
db
.
close
(
function
()
{});
});
d
=
((
new
Date
)
-
t0
)
/
1000
;
puts
(
"**** "
+
d
+
"s to fetch "
+
rows
+
" rows ("
+
(
rows
/
d
)
+
"/s)"
);
return
;
...
...
@@ -35,7 +35,7 @@ function getRows() {
}
function
createTable
(
db
,
callback
)
{
db
.
prepare
(
"CREATE TABLE t1 (id INTEGER PRIMARY KEY, alpha INTEGER)"
,
function
(
error
,
statement
)
{
db
.
prepare
AndStep
(
"CREATE TABLE t1 (id INTEGER PRIMARY KEY, alpha INTEGER)"
,
function
(
error
,
statement
)
{
if
(
error
)
throw
error
;
callback
();
});
...
...
@@ -47,8 +47,6 @@ function onInsert(error, info) {
var
d
;
if
(
error
)
throw
error
;
assert
.
ok
(
info
&&
info
.
last_inserted_id
>
0
,
'Last inserted ID loading failed'
);
if
(
++
rows
==
total
)
{
d
=
((
new
Date
)
-
t0
)
/
1000
;
puts
(
"**** "
+
d
+
"s to insert "
+
rows
+
" rows ("
+
(
rows
/
d
)
+
"/s)"
);
...
...
@@ -60,9 +58,7 @@ db.open(':memory:', function () {
createTable
(
db
,
function
()
{
t0
=
new
Date
();
for
(
var
i
=
0
;
i
<
total
;
i
++
)
{
db
.
prepare
(
"INSERT INTO t1 (alpha) VALUES (1)"
,
onInsert
,
sqlite
.
EXEC_LAST_INSERT_ID
);
db
.
prepareAndStep
(
"INSERT INTO t1 (alpha) VALUES (1)"
,
onInsert
);
}
});
});
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment