-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpointer_release.c
More file actions
executable file
·47 lines (33 loc) · 1.05 KB
/
pointer_release.c
File metadata and controls
executable file
·47 lines (33 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include <stdio.h>
#include <stdlib.h>
#include "headers/utils.h"
#include "headers/storman.h"
#include "headers/lists.h"
int pointer_release(void ** ptr_addr){
struct zone *curr_zone=malloc(sizeof(struct zone));
struct block *curr_block=malloc(sizeof(struct block));
struct list_blockPtr *curr_ptr=malloc(sizeof(struct list_blockPtr));
/*
* se ptr_addr non punta a un puntatore di storman non faccio niente e ritorno 1
*/
if(!search(ptr_addr,&curr_zone,&curr_block,& curr_ptr))
return 1;
else{
/*
* Controllo se il blocco di *ptr_addr ha un solo puntatore
* in quel caso non posso rilasciare *ptr_addr e ritorno 2
*/
if( curr_ptr==curr_block->ptr_listhead //se è il primo elemento della lista
&& !curr_ptr->next ) //ed è anche l'ultimo
//ovvero è l'unico elemento della lista
return 2;
else{
/*
* se ci sono altri puntatori al blocco rilascio il puntatore
*/
delete(curr_block->ptr_listhead, curr_ptr );
*ptr_addr=NULL;
return 0;
}
}
}