Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
Kestrel Collaboration
Kestrel Firmware
serial
Commits
b2263a78
Commit
b2263a78
authored
14 years ago
by
William Woodall
Browse files
Options
Download
Email Patches
Plain Diff
Fixed some potential memory leaks. Also, added a possible fix for the PARTIY_NONE debackle.
parent
1ca16c47
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
25 additions
and
5 deletions
+25
-5
include/serial.h
include/serial.h
+14
-1
src/serial.cpp
src/serial.cpp
+11
-4
No files found.
include/serial.h
View file @
b2263a78
...
...
@@ -53,11 +53,24 @@
TypeName(const TypeName&); \
void operator=(const TypeName&)
// If on Windows undefine the PARITY_* defines that are in winbase.h
#ifdef PARTIY_NONE
#undef PARITY_NONE
#endif
#ifdef PARTIY_ODD
#undef PARITY_ODD
#endif
#ifdef PARTIY_EVEN
#undef PARITY_EVEN
#endif
// DEFINES
#define DEFAULT_BAUDRATE 9600
#define DEFAULT_TIMEOUT 0.0
#define DEFAULT_BYTESIZE EIGHTBITS
#define DEFAULT_PARITY NONE
#define DEFAULT_PARITY
PARITY_
NONE
#define DEFAULT_STOPBITS STOPBITS_ONE
#define DEFAULT_FLOWCONTROL FLOWCONTROL_NONE
...
...
This diff is collapsed.
Click to expand it.
src/serial.cpp
View file @
b2263a78
...
...
@@ -159,6 +159,8 @@ void Serial::init() {
Serial
::~
Serial
()
{
this
->
close
();
if
(
this
->
timeout
!=
NULL
)
delete
this
->
timeout
;
}
void
Serial
::
open
()
{
...
...
@@ -185,8 +187,11 @@ void Serial::open() {
void
Serial
::
close
()
{
// Cancel the current timeout timer and async reads
this
->
timeout_timer
.
cancel
();
this
->
serial_port
->
cancel
();
this
->
serial_port
->
close
();
if
(
this
->
serial_port
!=
NULL
)
{
this
->
serial_port
->
cancel
();
this
->
serial_port
->
close
();
delete
this
->
serial_port
;
}
}
const
int
Serial
::
read
(
char
*
buffer
,
int
size
)
{
...
...
@@ -219,7 +224,7 @@ const std::string Serial::read(int size) {
char
*
serial_buffer
=
new
char
[
size
];
int
bytes_read_
=
this
->
read
(
serial_buffer
,
size
);
std
::
string
return_str
(
serial_buffer
,
(
std
::
size_t
)
bytes_read_
);
delete
serial_buffer
;
delete
[]
serial_buffer
;
return
return_str
;
}
...
...
@@ -248,7 +253,7 @@ const int Serial::write(std::string data) {
char
*
cstr
=
new
char
[
data
.
size
()
+
1
];
std
::
strcpy
(
cstr
,
data
.
c_str
());
int
bytes_wrote
=
this
->
write
(
cstr
,
data
.
length
());
delete
cstr
;
delete
[]
cstr
;
return
bytes_wrote
;
}
...
...
@@ -277,6 +282,8 @@ void Serial::setTimeoutMilliseconds(long timeout) {
if
(
timeout
>
0
)
{
this
->
timeout
=
new
boost
::
posix_time
::
milliseconds
(
timeout
);
}
else
{
if
(
this
->
timeout
!=
NULL
)
delete
this
->
timeout
;
this
->
timeout
=
NULL
;
}
...
...
This diff is collapsed.
Click to expand it.
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