Coverage Report

Created: 2025-11-24 06:37

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/sudo/lib/eventlog/eventlog_free.c
Line
Count
Source
1
/*
2
 * SPDX-License-Identifier: ISC
3
 *
4
 * Copyright (c) 2020, 2023, 2025 Todd C. Miller <Todd.Miller@sudo.ws>
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
3.64k
{
39
3.64k
    size_t i;
40
3.64k
    debug_decl(eventlog_free_contents, SUDO_DEBUG_UTIL);
41
42
3.64k
    free(evlog->iolog_path);
43
3.64k
    free(evlog->command);
44
3.64k
    free(evlog->cwd);
45
3.64k
    free(evlog->runchroot);
46
3.64k
    free(evlog->runcwd);
47
3.64k
    free(evlog->rungroup);
48
3.64k
    free(evlog->runuser);
49
3.64k
    free(evlog->peeraddr);
50
3.64k
    free(evlog->signal_name);
51
3.64k
    free(evlog->source);
52
3.64k
    if (evlog->submitenv != NULL) {
53
241
  for (i = 0; evlog->submitenv[i] != NULL; i++)
54
203
      free(evlog->submitenv[i]);
55
38
  free(evlog->submitenv);
56
38
    }
57
3.64k
    free(evlog->submithost);
58
3.64k
    free(evlog->submituser);
59
3.64k
    free(evlog->submitgroup);
60
3.64k
    free(evlog->ttyname);
61
3.64k
    if (evlog->runargv != NULL) {
62
245
  for (i = 0; evlog->runargv[i] != NULL; i++)
63
203
      free(evlog->runargv[i]);
64
42
  free(evlog->runargv);
65
42
    }
66
3.64k
    if (evlog->runenv != NULL) {
67
443
  for (i = 0; evlog->runenv[i] != NULL; i++)
68
394
      free(evlog->runenv[i]);
69
49
  free(evlog->runenv);
70
49
    }
71
3.64k
    if (evlog->env_add != NULL) {
72
241
  for (i = 0; evlog->env_add[i] != NULL; i++)
73
203
      free(evlog->env_add[i]);
74
38
  free(evlog->env_add);
75
38
    }
76
77
3.64k
    debug_return;
78
3.64k
}
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
3.64k
{
86
3.64k
    debug_decl(eventlog_free, SUDO_DEBUG_UTIL);
87
88
3.64k
    if (evlog != NULL) {
89
3.64k
  eventlog_free_contents(evlog);
90
3.64k
  free(evlog);
91
3.64k
    }
92
93
3.64k
    debug_return;
94
3.64k
}