Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
malloc
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD 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
Daniel Shchur
malloc
Commits
63b6fa66
Commit
63b6fa66
authored
5 years ago
by
DocQuantum
Browse files
Options
Downloads
Patches
Plain Diff
Free now checks for null pointers, change bit is more effiecient
parent
a251199b
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
mm.c
+14
-2
14 additions, 2 deletions
mm.c
with
14 additions
and
2 deletions
mm.c
+
14
−
2
View file @
63b6fa66
...
...
@@ -167,12 +167,20 @@ void *mm_malloc(size_t size)
/*
* mm_free - Free a block
*
* Given the alloced bit is set, get header and increment by 1
* since that essentially sets the bit to 1 or free, else print
* error to stderr.
*/
/* $begin mmfree */
void
mm_free
(
void
*
bp
)
{
if
(
bp
==
NULL
){
fprintf
(
stderr
,
"Error: memory not alloced or corrupted"
);
}
if
(
!
GET_ALLOC
(
HDRP
(
bp
))){
*
(
size_t
*
)(
HDRP
(
bp
)
)
=
*
(
size_t
*
)(
HDRP
(
bp
)
)
+
1
;
*
HDRP
(
bp
)
=
*
HDRP
(
bp
)
|
1
;
}
else
{
fprintf
(
stderr
,
"Error: memory not alloced or corrupted"
);
}
...
...
@@ -183,10 +191,14 @@ void mm_free(void *bp)
/*
* mm_realloc - naive implementation of mm_realloc
*
* Given an alloced pointer, get size, add to that size, pass to malloc to
* get new block.
*
*/
void
*
mm_realloc
(
void
*
ptr
,
size_t
size
)
{
/* You need to implement this function. */
return
NULL
;
}
...
...
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