Skip to content

Commit 086e698

Browse files
committed
associate audit_rule_free_data with audit_rule_create_data for cleanup
1 parent ef42246 commit 086e698

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

lib/libaudit.h

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,14 @@
4040
#ifndef __wur
4141
# define __wur
4242
#endif
43+
// malloc and free assignments
44+
#ifndef __attr_dealloc
45+
# define __attr_dealloc(dealloc, argno)
46+
# define __attr_dealloc_free
47+
#endif
48+
#ifndef __attribute_malloc__
49+
# define __attribute_malloc__
50+
#endif
4351

4452
#include <audit_logging.h>
4553

@@ -281,24 +289,24 @@ int audit_delete_rule_data(int fd, struct audit_rule_data *rule,
281289
int flags, int action);
282290

283291
/* Rule-building helper functions */
292+
/* Deallocates the audit_rule_rule object, and any associated resources */
293+
void audit_rule_free_data(struct audit_rule_data *rule);
284294
/* Heap-allocates and initializes an audit_rule_data */
285-
struct audit_rule_data *audit_rule_create_data(void);
295+
struct audit_rule_data *audit_rule_create_data(void)
296+
__attribute_malloc__ __attr_dealloc (audit_rule_free_data, 1);
286297
/* Initializes an existing audit_rule_data struct */
287298
void audit_rule_init_data(struct audit_rule_data *rule);
288299
int audit_rule_syscallbyname_data(struct audit_rule_data *rule,
289300
const char *scall);
290301
int audit_rule_io_uringbyname_data(struct audit_rule_data *rule,
291302
const char *scall);
292303

293-
/* Note that the following function takes a **, where audit_rule_fieldpair()
294-
* takes just a *. That structure may need to be reallocated as a result of
295-
* adding new fields */
304+
/* Note that the following function takes a **. That structure may need
305+
* to be reallocated as a result of adding new fields */
296306
int audit_rule_fieldpair_data(struct audit_rule_data **rulep,
297307
char *pair, int flags);
298308
int audit_rule_interfield_comp_data(struct audit_rule_data **rulep,
299309
char *pair, int flags);
300-
/* Deallocates the audit_rule_rule object, and any associated resources */
301-
void audit_rule_free_data(struct audit_rule_data *rule);
302310

303311
/* Capability testing functions */
304312
int audit_can_control(void);

0 commit comments

Comments
 (0)