Skip to content

Commit de38b7f

Browse files
committed
block: fix split_block + fix mallocs size
1 parent e5fb891 commit de38b7f

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

src/network/block.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33

44
struct block_register *generate_blocks(size_t nb_blks) {
55
struct block_register *blks = malloc(sizeof(struct block_register));
6-
blks->blks = malloc(nb_blks * sizeof(struct block *));
6+
blks->blks = malloc((34 + nb_blks) * sizeof(struct block *));
77
blks->nb_blocks = nb_blks;
88
return blks;
99
}
1010

1111
struct block *generate_block(unsigned short id, size_t size, size_t node_address,
1212
size_t virtual_address, char free) {
13-
struct block *blk = malloc(sizeof(struct block));
13+
struct block *blk = malloc(64 + sizeof(struct block));
1414
blk->id = id;
1515
blk->size = size;
1616
blk->node_address = node_address;
@@ -44,10 +44,11 @@ struct block_register *init_nodes_same_size(unsigned short nb_nodes, size_t size
4444
struct block *split_block_u(struct block *b, size_t size) {
4545
if (!b) {
4646
printf("FATAL ALLOCATION ERROR\n");
47+
return NULL;
4748
}
48-
if (b->size < size) {
49+
if (b->size > size) {
50+
size_t su = b->size - size;
4951
b->size = size;
50-
size_t su = size - b->size;
5152
struct block *b_next = b->next;
5253
add_block(b, b->id, su, b->node_address + size, b->virtual_address + size, 0);
5354
b->next->next = b_next;

0 commit comments

Comments
 (0)