Coverage Report

Created: 2025-07-11 06:58

/src/sudo/lib/eventlog/eventlog_free.c
Line
Count
Source
1
/*
2
 * SPDX-License-Identifier: ISC
3
 *
4
 * Copyright (c) 2020 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
/*
24
 * This is an open source non-commercial project. Dear PVS-Studio, please check it.
25
 * PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
26
 */
27
28
#include <config.h>
29
30
#include <stdio.h>
31
#include <stdlib.h>
32
33
#include <sudo_compat.h>
34
#include <sudo_debug.h>
35
#include <sudo_eventlog.h>
36
#include <sudo_util.h>
37
38
/*
39
 * Free the strings in a struct eventlog.
40
 */
41
void
42
eventlog_free(struct eventlog *evlog)
43
3.63k
{
44
3.63k
    size_t i;
45
3.63k
    debug_decl(eventlog_free, SUDO_DEBUG_UTIL);
46
47
3.63k
    if (evlog != NULL) {
48
3.63k
  free(evlog->iolog_path);
49
3.63k
  free(evlog->command);
50
3.63k
  free(evlog->cwd);
51
3.63k
  free(evlog->runchroot);
52
3.63k
  free(evlog->runcwd);
53
3.63k
  free(evlog->rungroup);
54
3.63k
  free(evlog->runuser);
55
3.63k
  free(evlog->peeraddr);
56
3.63k
  free(evlog->signal_name);
57
3.63k
  free(evlog->source);
58
3.63k
  if (evlog->submitenv != NULL) {
59
241
      for (i = 0; evlog->submitenv[i] != NULL; i++)
60
203
    free(evlog->submitenv[i]);
61
38
      free(evlog->submitenv);
62
38
  }
63
3.63k
  free(evlog->submithost);
64
3.63k
  free(evlog->submituser);
65
3.63k
  free(evlog->submitgroup);
66
3.63k
  free(evlog->ttyname);
67
3.63k
  if (evlog->runargv != NULL) {
68
241
      for (i = 0; evlog->runargv[i] != NULL; i++)
69
203
    free(evlog->runargv[i]);
70
38
      free(evlog->runargv);
71
38
  }
72
3.63k
  if (evlog->runenv != NULL) {
73
443
      for (i = 0; evlog->runenv[i] != NULL; i++)
74
394
    free(evlog->runenv[i]);
75
49
      free(evlog->runenv);
76
49
  }
77
3.63k
  if (evlog->env_add != NULL) {
78
241
      for (i = 0; evlog->env_add[i] != NULL; i++)
79
203
    free(evlog->env_add[i]);
80
38
      free(evlog->env_add);
81
38
  }
82
3.63k
  free(evlog);
83
3.63k
    }
84
85
3.63k
    debug_return;
86
3.63k
}