-
Notifications
You must be signed in to change notification settings - Fork 0
/
exitcleanup.c
54 lines (50 loc) · 953 Bytes
/
exitcleanup.c
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
48
49
50
51
52
53
54
#include "shell.h"
#include "alias.h"
#include "shellvars.h"
char ***getenviron();
ShellVar **getspecial();
ShellVar **getvars();
AliasData **getalist();
/**
* exitcleanup - cleans up various vars before exiting
* @av: argument list to free (if any)
* Return: void
*/
void exitcleanup(char **av)
{
ShellVar *sptr = *(getspecial()), *snext;
AliasData *aptr = *(getalist()), *anext;
char **environ = *(getenviron());
int i = 0;
if (av != NULL)
for (i = 0; av[i] != NULL; i++)
free(av[i]);
i = 0;
while (environ[i] != NULL)
free(environ[i++]);
free(environ);
while (sptr != NULL)
{
free(sptr->val);
free(sptr->name);
sptr = sptr->next;
}
free(*(getspecial()));
sptr = *(getvars());
while (sptr != NULL)
{
free(sptr->val);
free(sptr->name);
snext = sptr->next;
free(sptr);
sptr = snext;
}
while (aptr != NULL)
{
free(aptr->val);
free(aptr->name);
anext = aptr->next;
free(aptr);
aptr = anext;
}
}