Commit | Line | Data |
---|---|---|
76fcf151 | 1 | /* |
ab5be9fa | 2 | * Copyright (C) 2018 Jérémie Galarneau <jeremie.galarneau@efficios.com> |
76fcf151 | 3 | * |
ab5be9fa | 4 | * SPDX-License-Identifier: LGPL-2.1-only |
76fcf151 | 5 | * |
76fcf151 JG |
6 | */ |
7 | ||
8 | #include <lttng/event-internal.h> | |
9 | #include <common/error.h> | |
10 | ||
76fcf151 JG |
11 | struct lttng_event *lttng_event_copy(const struct lttng_event *event) |
12 | { | |
13 | struct lttng_event *new_event; | |
14 | struct lttng_event_extended *new_event_extended; | |
15 | ||
16 | new_event = zmalloc(sizeof(*event)); | |
17 | if (!new_event) { | |
18 | PERROR("Error allocating event structure"); | |
19 | goto end; | |
20 | } | |
21 | ||
22 | /* Copy the content of the old event. */ | |
23 | memcpy(new_event, event, sizeof(*event)); | |
24 | ||
25 | /* | |
26 | * We need to create a new extended since the previous pointer is now | |
27 | * invalid. | |
28 | */ | |
29 | new_event_extended = zmalloc(sizeof(*new_event_extended)); | |
30 | if (!new_event_extended) { | |
31 | PERROR("Error allocating event extended structure"); | |
32 | goto error; | |
33 | } | |
34 | ||
35 | new_event->extended.ptr = new_event_extended; | |
36 | end: | |
37 | return new_event; | |
38 | error: | |
39 | free(new_event); | |
37750a61 | 40 | new_event = NULL; |
76fcf151 JG |
41 | goto end; |
42 | } |