Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sudo-project
GitHub Repository: sudo-project/sudo
Path: blob/main/lib/eventlog/eventlog_free.c
1532 views
1
/*
2
* SPDX-License-Identifier: ISC
3
*
4
* Copyright (c) 2020, 2023, 2025 Todd C. Miller <[email protected]>
5
*
6
* Permission to use, copy, modify, and distribute this software for any
7
* purpose with or without fee is hereby granted, provided that the above
8
* copyright notice and this permission notice appear in all copies.
9
*
10
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17
*
18
* Sponsored in part by the Defense Advanced Research Projects
19
* Agency (DARPA) and Air Force Research Laboratory, Air Force
20
* Materiel Command, USAF, under agreement number F39502-99-1-0512.
21
*/
22
23
#include <config.h>
24
25
#include <stdio.h>
26
#include <stdlib.h>
27
28
#include <sudo_compat.h>
29
#include <sudo_debug.h>
30
#include <sudo_eventlog.h>
31
#include <sudo_util.h>
32
33
/*
34
* Free the strings in a struct eventlog.
35
*/
36
void
37
eventlog_free_contents(struct eventlog *evlog)
38
{
39
size_t i;
40
debug_decl(eventlog_free_contents, SUDO_DEBUG_UTIL);
41
42
free(evlog->iolog_path);
43
free(evlog->command);
44
free(evlog->cwd);
45
free(evlog->runchroot);
46
free(evlog->runcwd);
47
free(evlog->rungroup);
48
free(evlog->runuser);
49
free(evlog->peeraddr);
50
free(evlog->signal_name);
51
free(evlog->source);
52
if (evlog->submitenv != NULL) {
53
for (i = 0; evlog->submitenv[i] != NULL; i++)
54
free(evlog->submitenv[i]);
55
free(evlog->submitenv);
56
}
57
free(evlog->submithost);
58
free(evlog->submituser);
59
free(evlog->submitgroup);
60
free(evlog->ttyname);
61
if (evlog->runargv != NULL) {
62
for (i = 0; evlog->runargv[i] != NULL; i++)
63
free(evlog->runargv[i]);
64
free(evlog->runargv);
65
}
66
if (evlog->runenv != NULL) {
67
for (i = 0; evlog->runenv[i] != NULL; i++)
68
free(evlog->runenv[i]);
69
free(evlog->runenv);
70
}
71
if (evlog->env_add != NULL) {
72
for (i = 0; evlog->env_add[i] != NULL; i++)
73
free(evlog->env_add[i]);
74
free(evlog->env_add);
75
}
76
77
debug_return;
78
}
79
80
/*
81
* Free the strings in a struct eventlog and the eventlog container itself.
82
*/
83
void
84
eventlog_free(struct eventlog *evlog)
85
{
86
debug_decl(eventlog_free, SUDO_DEBUG_UTIL);
87
88
if (evlog != NULL) {
89
eventlog_free_contents(evlog);
90
free(evlog);
91
}
92
93
debug_return;
94
}
95
96