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
683e12d2
Commit
683e12d2
authored
5 years ago
by
bsbaliga
Committed by
William Woodall
5 years ago
Browse files
Options
Download
Email Patches
Plain Diff
Fix memory leak when exception is thrown by impl classes in (#198)
Serial::read() vector and string variants.
parent
fba8d81b
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
2 deletions
+18
-2
src/serial.cc
src/serial.cc
+18
-2
No files found.
src/serial.cc
View file @
683e12d2
...
...
@@ -132,7 +132,16 @@ Serial::read (std::vector<uint8_t> &buffer, size_t size)
{
ScopedReadLock
lock
(
this
->
pimpl_
);
uint8_t
*
buffer_
=
new
uint8_t
[
size
];
size_t
bytes_read
=
this
->
pimpl_
->
read
(
buffer_
,
size
);
size_t
bytes_read
=
0
;
try
{
bytes_read
=
this
->
pimpl_
->
read
(
buffer_
,
size
);
}
catch
(
const
std
::
exception
&
e
)
{
delete
[]
buffer_
;
throw
;
}
buffer
.
insert
(
buffer
.
end
(),
buffer_
,
buffer_
+
bytes_read
);
delete
[]
buffer_
;
return
bytes_read
;
...
...
@@ -143,7 +152,14 @@ Serial::read (std::string &buffer, size_t size)
{
ScopedReadLock
lock
(
this
->
pimpl_
);
uint8_t
*
buffer_
=
new
uint8_t
[
size
];
size_t
bytes_read
=
this
->
pimpl_
->
read
(
buffer_
,
size
);
size_t
bytes_read
=
0
;
try
{
bytes_read
=
this
->
pimpl_
->
read
(
buffer_
,
size
);
}
catch
(
const
std
::
exception
&
e
)
{
delete
[]
buffer_
;
throw
;
}
buffer
.
append
(
reinterpret_cast
<
const
char
*>
(
buffer_
),
bytes_read
);
delete
[]
buffer_
;
return
bytes_read
;
...
...
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