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
1c2210b5
Commit
1c2210b5
authored
Feb 18, 2011
by
Konstantin Käfer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
properly close database handles in all circumstances
parent
32b1b552
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
31 additions
and
4 deletions
+31
-4
database.cc
src/database.cc
+11
-0
database.h
src/database.h
+4
-1
statement.cc
src/statement.cc
+12
-2
statement.h
src/statement.h
+4
-1
No files found.
src/database.cc
View file @
1c2210b5
...
...
@@ -279,6 +279,17 @@ void Database::Wrap(Handle<Object> handle) {
handle_
.
MakeWeak
(
this
,
Destruct
);
}
inline
void
Database
::
MakeWeak
(
void
)
{
handle_
.
MakeWeak
(
this
,
Destruct
);
}
void
Database
::
Unref
()
{
assert
(
!
handle_
.
IsEmpty
());
assert
(
!
handle_
.
IsWeak
());
assert
(
refs_
>
0
);
if
(
--
refs_
==
0
)
{
MakeWeak
();
}
}
void
Database
::
Destruct
(
Persistent
<
Value
>
value
,
void
*
data
)
{
Database
*
db
=
static_cast
<
Database
*>
(
data
);
if
(
db
->
handle
)
{
...
...
src/database.h
View file @
1c2210b5
...
...
@@ -77,7 +77,8 @@ protected:
}
~
Database
()
{
fprintf
(
stderr
,
"Calling destructor
\n
"
);
assert
(
handle
==
NULL
);
fprintf
(
stderr
,
"Deleted Database
\n
"
);
}
static
Handle
<
Value
>
New
(
const
Arguments
&
args
);
...
...
@@ -95,6 +96,8 @@ protected:
static
int
EIO_AfterClose
(
eio_req
*
req
);
void
Wrap
(
Handle
<
Object
>
handle
);
inline
void
MakeWeak
();
virtual
void
Unref
();
static
void
Destruct
(
Persistent
<
Value
>
value
,
void
*
data
);
static
int
EIO_Destruct
(
eio_req
*
req
);
static
int
EIO_AfterDestruct
(
eio_req
*
req
);
...
...
src/statement.cc
View file @
1c2210b5
...
...
@@ -100,7 +100,7 @@ Handle<Value> Statement::New(const Arguments& args) {
void
Statement
::
EIO_BeginPrepare
(
Baton
*
baton
)
{
assert
(
baton
->
db
->
open
);
assert
(
!
baton
->
db
->
locked
);
//
static_cast<PrepareBaton*>(baton)->stmt->Ref();
static_cast
<
PrepareBaton
*>
(
baton
)
->
stmt
->
Ref
();
ev_ref
(
EV_DEFAULT_UC
);
fprintf
(
stderr
,
"Prepare started
\n
"
);
eio_custom
(
EIO_Prepare
,
EIO_PRI_DEFAULT
,
EIO_AfterPrepare
,
baton
);
...
...
@@ -191,9 +191,19 @@ void Statement::Wrap(Handle<Object> handle) {
handle_
.
MakeWeak
(
this
,
Destruct
);
}
inline
void
Statement
::
MakeWeak
(
void
)
{
handle_
.
MakeWeak
(
this
,
Destruct
);
}
void
Statement
::
Unref
()
{
assert
(
!
handle_
.
IsEmpty
());
assert
(
!
handle_
.
IsWeak
());
assert
(
refs_
>
0
);
if
(
--
refs_
==
0
)
{
MakeWeak
();
}
}
void
Statement
::
Destruct
(
Persistent
<
Value
>
value
,
void
*
data
)
{
Statement
*
stmt
=
static_cast
<
Statement
*>
(
data
);
fprintf
(
stderr
,
"Auto-Finalizing handle started
\n
"
);
if
(
stmt
->
handle
)
{
eio_custom
(
EIO_Destruct
,
EIO_PRI_DEFAULT
,
EIO_AfterDestruct
,
stmt
);
ev_ref
(
EV_DEFAULT_UC
);
...
...
src/statement.h
View file @
1c2210b5
...
...
@@ -52,6 +52,7 @@ public:
~
Statement
()
{
fprintf
(
stderr
,
"Deleted Statement
\n
"
);
assert
(
handle
==
NULL
);
db
->
pending
--
;
Database
::
Process
(
db
);
db
->
Unref
();
...
...
@@ -63,7 +64,9 @@ protected:
static
int
EIO_AfterPrepare
(
eio_req
*
req
);
void
Wrap
(
Handle
<
Object
>
handle
);
static
void
Destruct
(
Persistent
<
Value
>
value
,
void
*
data
);
inline
void
MakeWeak
();
virtual
void
Unref
();
static
void
Destruct
(
Persistent
<
Value
>
value
,
void
*
data
);
static
int
EIO_Destruct
(
eio_req
*
req
);
static
int
EIO_AfterDestruct
(
eio_req
*
req
);
...
...
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