Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
E
ECSS Services
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
AcubeSat-OBC
ECSS Services
Commits
1768a374
"git@git.noc.ruhr-uni-bochum.de:pohlsvkp/teqp_fork_old.git" did not exist on "0b711e81e2e41f40be37481d5d79572bf766f569"
Unverified
Commit
1768a374
authored
6 years ago
by
Dimitrios Stoupis
Browse files
Options
Downloads
Patches
Plain Diff
Make realloc safer
parent
cef2deb7
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/Services/MemMangService.cpp
+10
-6
10 additions, 6 deletions
src/Services/MemMangService.cpp
with
10 additions
and
6 deletions
src/Services/MemMangService.cpp
+
10
−
6
View file @
1768a374
...
...
@@ -28,7 +28,7 @@ void MemoryManagementService::RawDataMemoryManagement::loadRawData(Message &requ
uint8_t
memoryID
=
request
.
readEnum8
();
// Read the memory ID from the request
// Variable declaration
uint8_t
*
readData
=
nullptr
;
// Pointer to store the
data read from the memory
uint8_t
*
readData
=
nullptr
,
*
tempMemory
=
nullptr
;
// Pointer to store the
received data
uint16_t
iterationCount
=
0
;
// Get the iteration count
uint16_t
dataLength
=
0
;
// Data length to read (updated for each new iteration)
uint16_t
allocatedLength
=
0
;
// Length allocated for the readData array
...
...
@@ -44,11 +44,13 @@ void MemoryManagementService::RawDataMemoryManagement::loadRawData(Message &requ
// Allocate more array space if needed
if
(
allocatedLength
<
dataLength
)
{
readData
=
static_cast
<
uint8_t
*>
(
realloc
(
readData
,
dataLength
));
if
(
readData
==
nullptr
)
{
tempMemory
=
static_cast
<
uint8_t
*>
(
realloc
(
readData
,
dataLength
));
if
(
tempMemory
==
nullptr
)
{
// todo: Add error logging and reporting
free
(
readData
);
return
;
}
else
{
readData
=
tempMemory
;
}
}
...
...
@@ -75,7 +77,7 @@ void MemoryManagementService::RawDataMemoryManagement::dumpRawData(Message &requ
Message
report
=
mainService
->
createTM
(
6
);
// Variable declaration
uint8_t
*
readData
=
nullptr
;
// Pointer to store the
data read from the memory
uint8_t
*
readData
=
nullptr
,
*
tempMemory
=
nullptr
;
;
// Pointer to store the
read data
uint16_t
iterationCount
=
0
;
// Get the iteration count
uint16_t
readLength
=
0
;
// Data length to read (updated for each new iteration)
uint16_t
allocatedLength
=
0
;
// Length allocated for the readData array
...
...
@@ -98,11 +100,13 @@ void MemoryManagementService::RawDataMemoryManagement::dumpRawData(Message &requ
// Allocate more array space if needed
if
(
allocatedLength
<
readLength
)
{
readData
=
static_cast
<
uint8_t
*>
(
realloc
(
readData
,
readLength
));
if
(
readData
==
nullptr
)
{
tempMemory
=
static_cast
<
uint8_t
*>
(
realloc
(
readData
,
readLength
));
if
(
tempMemory
==
nullptr
)
{
// todo: Add error logging and reporting
free
(
readData
);
return
;
}
else
{
readData
=
tempMemory
;
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment