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
297ff09f
Commit
297ff09f
authored
Mar 24, 2010
by
Orlando Vazquez
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
sort out crashes due to errornous pointer invalidation
parent
e3f9d5e9
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
33 additions
and
14 deletions
+33
-14
sqlite3_bindings.cc
sqlite3_bindings.cc
+33
-14
No files found.
sqlite3_bindings.cc
View file @
297ff09f
...
@@ -18,6 +18,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
...
@@ -18,6 +18,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include <string.h>
#include <string.h>
#include <stdlib.h>
#include <stdlib.h>
#include <stdio.h>
#include <stdio.h>
#include <unistd.h>
#include <v8.h>
#include <v8.h>
#include <node.h>
#include <node.h>
...
@@ -163,7 +164,13 @@ protected:
...
@@ -163,7 +164,13 @@ protected:
struct
open_request
*
open_req
=
(
struct
open_request
*
)(
req
->
data
);
struct
open_request
*
open_req
=
(
struct
open_request
*
)(
req
->
data
);
sqlite3
**
dbptr
=
open_req
->
dbo
->
GetDBPtr
();
sqlite3
**
dbptr
=
open_req
->
dbo
->
GetDBPtr
();
int
rc
=
sqlite3_open
(
open_req
->
filename
,
dbptr
);
int
rc
=
sqlite3_open_v2
(
open_req
->
filename
,
dbptr
,
SQLITE_OPEN_READWRITE
|
SQLITE_OPEN_CREATE
|
SQLITE_OPEN_FULLMUTEX
,
NULL
);
req
->
result
=
rc
;
req
->
result
=
rc
;
// sqlite3 *db = *dbptr;
// sqlite3 *db = *dbptr;
...
@@ -799,7 +806,7 @@ protected:
...
@@ -799,7 +806,7 @@ protected:
Local
<
Value
>
argv
[
2
];
Local
<
Value
>
argv
[
2
];
if
(
step_req
->
error_msg
)
{
if
(
step_req
->
error_msg
)
{
argv
[
0
]
=
Exception
::
Error
(
String
::
New
(
step_req
->
error_msg
));
argv
[
0
]
=
Exception
::
Error
(
String
::
New
(
"some error"
));
}
}
else
{
else
{
argv
[
0
]
=
Local
<
Value
>::
New
(
Undefined
());
argv
[
0
]
=
Local
<
Value
>::
New
(
Undefined
());
...
@@ -812,24 +819,27 @@ protected:
...
@@ -812,24 +819,27 @@ protected:
Local
<
Object
>
row
=
Object
::
New
();
Local
<
Object
>
row
=
Object
::
New
();
for
(
int
i
=
0
;
i
<
step_req
->
column_count
;
i
++
)
{
for
(
int
i
=
0
;
i
<
step_req
->
column_count
;
i
++
)
{
assert
(
step_req
->
column_data
[
i
]);
assert
(
step_req
->
column_data
);
assert
(((
void
**
)
step_req
->
column_data
)[
i
]);
assert
(
step_req
->
column_names
[
i
]);
assert
(
step_req
->
column_names
[
i
]);
assert
(
step_req
->
column_types
[
i
]);
assert
(
step_req
->
column_types
[
i
]);
switch
(
step_req
->
column_types
[
i
])
{
switch
(
step_req
->
column_types
[
i
])
{
// XXX why does using String::New make v8 croak here?
case
SQLITE_INTEGER
:
case
SQLITE_INTEGER
:
row
->
Set
(
String
::
New
(
step_req
->
column_names
[
i
]),
row
->
Set
(
String
::
New
Symbol
((
char
*
)
step_req
->
column_names
[
i
]),
Int32
::
New
(
*
(
int
*
)
(
step_req
->
column_data
[
i
])));
Int32
::
New
(
*
(
int
*
)
(
step_req
->
column_data
[
i
])));
free
((
int
*
)(
step_req
->
column_data
[
i
]));
//
free((int*)(step_req->column_data[i]));
break
;
break
;
case
SQLITE_FLOAT
:
case
SQLITE_FLOAT
:
row
->
Set
(
String
::
New
(
step_req
->
column_names
[
i
]),
row
->
Set
(
String
::
New
(
step_req
->
column_names
[
i
]),
Number
::
New
(
*
(
double
*
)
(
step_req
->
column_data
[
i
])));
Number
::
New
(
*
(
double
*
)
(
step_req
->
column_data
[
i
])));
free
((
double
*
)(
step_req
->
column_data
[
i
]));
//
free((double*)(step_req->column_data[i]));
break
;
break
;
case
SQLITE_TEXT
:
case
SQLITE_TEXT
:
assert
(
strlen
((
char
*
)
step_req
->
column_data
[
i
]));
row
->
Set
(
String
::
New
(
step_req
->
column_names
[
i
]),
row
->
Set
(
String
::
New
(
step_req
->
column_names
[
i
]),
String
::
New
((
char
*
)
(
step_req
->
column_data
[
i
])));
String
::
New
((
char
*
)
(
step_req
->
column_data
[
i
])));
// don't free this pointer, it's owned by sqlite3
// don't free this pointer, it's owned by sqlite3
...
@@ -852,7 +862,8 @@ protected:
...
@@ -852,7 +862,8 @@ protected:
step_req
->
cb
.
Dispose
();
step_req
->
cb
.
Dispose
();
if
(
req
->
result
==
SQLITE_ROW
&&
step_req
->
column_count
)
{
if
(
req
->
result
==
SQLITE_DONE
&&
step_req
->
column_count
)
{
printf
(
"disposing of memory
\n
"
);
free
((
void
**
)
step_req
->
column_data
);
free
((
void
**
)
step_req
->
column_data
);
step_req
->
column_data
=
NULL
;
step_req
->
column_data
=
NULL
;
}
}
...
@@ -887,6 +898,7 @@ protected:
...
@@ -887,6 +898,7 @@ protected:
if
(
!
step_req
->
column_types
if
(
!
step_req
->
column_types
&&
!
step_req
->
column_names
)
{
&&
!
step_req
->
column_names
)
{
step_req
->
column_count
=
sqlite3_column_count
(
stmt
);
step_req
->
column_count
=
sqlite3_column_count
(
stmt
);
assert
(
step_req
->
column_count
);
step_req
->
column_types
=
step_req
->
column_types
=
(
int
*
)
calloc
(
step_req
->
column_count
,
sizeof
(
int
));
(
int
*
)
calloc
(
step_req
->
column_count
,
sizeof
(
int
));
step_req
->
column_names
=
step_req
->
column_names
=
...
@@ -912,9 +924,13 @@ protected:
...
@@ -912,9 +924,13 @@ protected:
switch
(
type
)
{
switch
(
type
)
{
case
SQLITE_INTEGER
:
{
case
SQLITE_INTEGER
:
{
int
*
value
=
(
int
*
)
malloc
(
sizeof
(
int
));
step_req
->
column_data
[
i
]
=
(
int
*
)
malloc
(
sizeof
(
int
));
*
value
=
sqlite3_column_int
(
stmt
,
i
);
int
value
=
sqlite3_column_int
(
stmt
,
i
);
step_req
->
column_data
[
i
]
=
value
;
if
(
!
step_req
->
column_data
[
i
])
{
printf
(
"zomg
\n
"
);
}
*
(
int
*
)(
step_req
->
column_data
[
i
])
=
value
;
// printf("addr was %p\n", step_req->column_data[i]);
assert
(
step_req
->
column_data
[
i
]);
}
}
break
;
break
;
...
@@ -937,18 +953,24 @@ protected:
...
@@ -937,18 +953,24 @@ protected:
break
;
break
;
default:
{
default:
{
printf
(
"unsupporto
\n
"
);
// unsupported type
// unsupported type
}
}
}
assert
(
step_req
->
column_data
[
i
]);
assert
(
step_req
->
column_data
[
i
]);
assert
(
step_req
->
column_names
[
i
]);
assert
(
step_req
->
column_names
[
i
]);
assert
(
step_req
->
column_types
[
i
]);
assert
(
step_req
->
column_types
[
i
]);
}
}
}
assert
(
step_req
->
column_data
);
assert
(
step_req
->
column_names
);
assert
(
step_req
->
column_types
);
}
}
else
if
(
rc
==
SQLITE_DONE
)
{
else
if
(
rc
==
SQLITE_DONE
)
{
// nothing to do in this case
// nothing to do in this case
printf
(
"done
\n
"
);
}
}
else
{
else
{
printf
(
"error
\n
"
);
step_req
->
error_msg
=
(
char
*
)
step_req
->
error_msg
=
(
char
*
)
sqlite3_errmsg
(
sqlite3_db_handle
(
*
sto
));
sqlite3_errmsg
(
sqlite3_db_handle
(
*
sto
));
}
}
...
@@ -968,9 +990,6 @@ protected:
...
@@ -968,9 +990,6 @@ protected:
if
(
!
step_req
)
{
if
(
!
step_req
)
{
sto
->
step_req
=
step_req
=
(
struct
step_request
*
)
sto
->
step_req
=
step_req
=
(
struct
step_request
*
)
calloc
(
1
,
sizeof
(
struct
step_request
));
calloc
(
1
,
sizeof
(
struct
step_request
));
step_req
->
column_types
=
NULL
;
step_req
->
column_names
=
NULL
;
step_req
->
column_data
=
NULL
;
}
}
if
(
!
step_req
)
{
if
(
!
step_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