Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Matt Johnston
dropbear
Commits
87373be9
Commit
87373be9
authored
Nov 19, 2015
by
Matt Johnston
Browse files
lazy allocation of circbuffer
parent
85d9672e
Changes
1
Hide whitespace changes
Inline
Side-by-side
circbuffer.c
View file @
87373be9
...
...
@@ -37,9 +37,8 @@ circbuffer * cbuf_new(unsigned int size) {
}
cbuf
=
(
circbuffer
*
)
m_malloc
(
sizeof
(
circbuffer
));
if
(
size
>
0
)
{
cbuf
->
data
=
(
unsigned
char
*
)
m_malloc
(
size
);
}
/* data is malloced on first write */
cbuf
->
data
=
NULL
;
cbuf
->
used
=
0
;
cbuf
->
readpos
=
0
;
cbuf
->
writepos
=
0
;
...
...
@@ -50,8 +49,10 @@ circbuffer * cbuf_new(unsigned int size) {
void
cbuf_free
(
circbuffer
*
cbuf
)
{
m_burn
(
cbuf
->
data
,
cbuf
->
size
);
m_free
(
cbuf
->
data
);
if
(
cbuf
->
data
)
{
m_burn
(
cbuf
->
data
,
cbuf
->
size
);
m_free
(
cbuf
->
data
);
}
m_free
(
cbuf
);
}
...
...
@@ -106,6 +107,11 @@ unsigned char* cbuf_writeptr(circbuffer *cbuf, unsigned int len) {
dropbear_exit
(
"Bad cbuf write"
);
}
if
(
!
cbuf
->
data
)
{
/* lazy allocation */
cbuf
->
data
=
(
unsigned
char
*
)
m_malloc
(
cbuf
->
size
);
}
return
&
cbuf
->
data
[
cbuf
->
writepos
];
}
...
...
Write
Preview
Supports
Markdown
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