Skip to content
Snippets Groups Projects
Verified Commit e43e63fd authored by iliya.saroukha's avatar iliya.saroukha :first_quarter_moon:
Browse files

fix: preventing "double-free" condition of a frame

parent 2deb7684
No related branches found
No related tags found
No related merge requests found
......@@ -42,7 +42,7 @@ static void frame_mark_free(int frame) {
allocator.nb_frames_used--;
}
static bool is_frame_free(int frame) {
bool is_frame_free(int frame) {
int idx_bmp = frame / 8;
return !(allocator.bitmap[idx_bmp] & (1 << (frame % 8)));
}
......@@ -71,8 +71,10 @@ void frame_init(uint_t RAM_in_KB) {
}
void frame_free(void *frame_addr) {
if (!is_frame_free(ADDR_TO_FRAME_NB(frame_addr))) {
frame_mark_free(ADDR_TO_FRAME_NB(frame_addr));
}
}
uint_t frame_total_free(void) {
return BITMAP_SIZE * 8 - allocator.nb_frames_used;
......@@ -117,25 +119,3 @@ void dbg_frame_allocator(struct terminal_t *term) {
return;
}
}
/*void dbg_frame_bmp(struct terminal_t *term) {*/
/* if (term_set_colours(term, YELLOW, BLACK) != 0) {*/
/* return;*/
/* }*/
/**/
/* int alloc = 0;*/
/* for (uint_t i = 0; i < BITMAP_SIZE; i++) {*/
/* if (!allocator.bitmap[i]) {*/
/* break;*/
/* }*/
/**/
/* alloc += allocator.bitmap[i];*/
/* kprintf(term, "%d ", allocator.bitmap[i]);*/
/* }*/
/**/
/* kprintf(term, "Number of frames allocated = %d\n", alloc);*/
/**/
/* if (term_set_colours(term, WHITE, BLACK) != 0) {*/
/* return;*/
/* }*/
/*}*/
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment