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
Felix Kopp
Ardix
Commits
040b5af5
Verified
Commit
040b5af5
authored
Aug 11, 2021
by
Felix Kopp
Browse files
malloc: poison heap when DEBUG is defined
parent
8293d937
Changes
1
Hide whitespace changes
Inline
Side-by-side
lib/malloc.c
View file @
040b5af5
...
...
@@ -220,6 +220,9 @@ void *malloc(size_t size)
cursor
=
blk_slice
(
&
generic_heap
,
cursor
,
size
);
generic_heap_free
-=
blk_get_size
(
cursor
);
ptr
=
cursor
->
data
;
# ifdef DEBUG
memset
(
cursor
->
data
,
0xaa
,
blk_get_size
(
cursor
));
# endif
}
mutex_unlock
(
&
generic_heap_lock
);
...
...
@@ -249,6 +252,9 @@ void *atomic_malloc(size_t size)
cursor
=
blk_slice
(
&
atomic_heap
,
cursor
,
size
);
atomic_heap_free
-=
blk_get_size
(
cursor
);
ptr
=
cursor
->
data
;
# ifdef DEBUG
memset
(
cursor
->
data
,
0xaa
,
blk_get_size
(
cursor
));
# endif
}
return
ptr
;
...
...
@@ -284,7 +290,12 @@ void free(void *ptr)
mutex_lock
(
&
generic_heap_lock
);
generic_heap_free
+=
blk_get_size
(
blk
);
blk_clear_alloc
(
blk
);
blk_try_merge
(
&
generic_heap
,
blk
);
blk
=
blk_try_merge
(
&
generic_heap
,
blk
);
# ifdef DEBUG
memset
(
&
blk
->
data
[
MIN_SIZE
],
0xaa
,
blk_get_size
(
blk
)
-
MIN_SIZE
);
# endif
mutex_unlock
(
&
generic_heap_lock
);
}
else
if
(
ptr
>=
atomic_heap_start
&&
ptr
<=
atomic_heap_end
)
{
if
(
!
blk_is_alloc
(
blk
))
...
...
@@ -293,7 +304,12 @@ void free(void *ptr)
atomic_enter
();
atomic_heap_free
+=
blk_get_size
(
blk
);
blk_clear_alloc
(
blk
);
blk_try_merge
(
&
atomic_heap
,
blk
);
blk
=
blk_try_merge
(
&
atomic_heap
,
blk
);
# ifdef DEBUG
memset
(
&
blk
->
data
[
MIN_SIZE
],
0xaa
,
blk_get_size
(
blk
)
-
MIN_SIZE
);
# endif
atomic_leave
();
}
else
{
__breakpoint
;
...
...
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