forked from mostsfa538/simple_shell
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelp_free.c
50 lines (44 loc) · 751 Bytes
/
help_free.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
#include "shell.h"
/**
* free_used_data - to avoid leake memory
* @data: data_t struct holds commands
*
*/
void free_used_data(data_t *data)
{
if (data->get_cmd)
free(data->get_cmd);
if (data->cmd)
free_grid_char(data->cmd);
if (data->run_cmd)
free(data->run_cmd);
data->run_cmd = NULL;
data->cmd = NULL;
data->get_cmd = NULL;
}
/**
* free_data - free all arrays in data_t struct
* @data: data_t struct holds commands
*
*/
void free_data(data_t *data)
{
free_used_data(data);
free_grid_char(data->env);
}
/**
* free_grid_char - frees a 2d arrays of char
* @arr: the 2d array
*
*/
void free_grid_char(char **arr)
{
int i;
if (arr != NULL)
{
for (i = 0; arr[i]; i++)
free(arr[i]);
free(arr);
arr = NULL;
}
}