Skip to content

Commit f3f73a2

Browse files
committed
leader: add if for checking not null block
1 parent e902218 commit f3f73a2

1 file changed

Lines changed: 11 additions & 9 deletions

File tree

src/network/leader.c

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,16 @@ int check_block_for_alloc(size_t *res_addr, struct block *b, size_t size, struc
3131
else if (size < b->size) {
3232
b->free = 1;
3333
b = split_block_u(b, size);
34-
struct allocation *a = malloc(sizeof(struct allocation));
35-
a->number_parts = 1;
36-
a->v_address_start = b->virtual_address;
37-
a->parts = malloc(a->number_parts * sizeof(struct allocation*));
38-
a->parts[0] = b;
39-
add_allocation(l_r->leader_reg, a);
40-
*res_addr = b->virtual_address;
41-
return 1;
34+
if (b) {
35+
struct allocation *a = malloc(sizeof(struct allocation));
36+
a->number_parts = 1;
37+
a->v_address_start = b->virtual_address;
38+
a->parts = malloc(a->number_parts * sizeof(struct allocation *));
39+
a->parts[0] = b;
40+
add_allocation(l_r->leader_reg, a);
41+
*res_addr = b->virtual_address;
42+
return 1;
43+
}
4244
}
4345
else {
4446

@@ -71,7 +73,7 @@ size_t alloc_memory(size_t size, struct leader_resources *l_r) {
7173
if (1 == check_block_for_alloc(&address, b, size, l_r))
7274
return address;
7375
}
74-
return 0;
76+
return 999999999;
7577
}
7678

7779
struct address_search *search_at_address(size_t address, struct leader_resources *l_r) {

0 commit comments

Comments
 (0)