Skip to content

Commit 22b1097

Browse files
authored
Fix compiler warnings (#437)
* Fix compiler warnings * auditctl: remove redundant assignment to retval in opt_trim
1 parent 63a274a commit 22b1097

File tree

2 files changed

+15
-12
lines changed

2 files changed

+15
-12
lines changed

lib/libaudit.c

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -789,7 +789,7 @@ int audit_add_watch_dir(int type, struct audit_rule_data **rulep,
789789
const char *path)
790790
{
791791
size_t len = strlen(path);
792-
struct audit_rule_data *rule = *rulep;
792+
struct audit_rule_data *rule = *rulep, *tmp;
793793

794794
if (rule && rule->field_count) {
795795
audit_msg(LOG_ERR, "Rule is not empty");
@@ -800,12 +800,16 @@ int audit_add_watch_dir(int type, struct audit_rule_data **rulep,
800800
return -1;
801801
}
802802

803-
*rulep = realloc(rule, len + sizeof(*rule));
804-
if (*rulep == NULL) {
803+
// Use a temporary pointer to prevent memory leaks
804+
tmp = realloc(rule, len + sizeof(*rule));
805+
if (tmp == NULL) {
805806
free(rule);
807+
*rulep = NULL;
806808
audit_msg(LOG_ERR, "Cannot realloc memory!");
807809
return -1;
808810
}
811+
812+
*rulep = tmp;
809813
rule = *rulep;
810814
memset(rule, 0, len + sizeof(*rule));
811815

@@ -830,6 +834,7 @@ int audit_add_watch_dir(int type, struct audit_rule_data **rulep,
830834
return 0;
831835
}
832836

837+
833838
int audit_add_rule_data(int fd, struct audit_rule_data *rule,
834839
int flags, int action)
835840
{
@@ -1621,7 +1626,7 @@ int audit_rule_fieldpair_data(struct audit_rule_data **rulep, const char *pair,
16211626
int field;
16221627
int vlen;
16231628
int offset;
1624-
struct audit_rule_data *rule = *rulep;
1629+
struct audit_rule_data *rule = *rulep, *tmp;
16251630

16261631
if (f == NULL)
16271632
return -EAU_FILTERMISSING;
@@ -1834,14 +1839,14 @@ int audit_rule_fieldpair_data(struct audit_rule_data **rulep, const char *pair,
18341839
rule->values[rule->field_count] = vlen;
18351840
offset = rule->buflen;
18361841
rule->buflen += vlen;
1837-
*rulep = realloc(rule, sizeof(*rule) + rule->buflen);
1838-
if (*rulep == NULL) {
1842+
tmp = realloc(rule, sizeof(*rule) + rule->buflen);
1843+
if (tmp == NULL) {
18391844
free(rule);
18401845
audit_msg(LOG_ERR, "Cannot realloc memory!");
18411846
return -3;
1842-
} else {
1843-
rule = *rulep;
18441847
}
1848+
*rulep = tmp;
1849+
rule = tmp;
18451850
strncpy(&rule->buf[offset], v, vlen);
18461851

18471852
break;

src/auditctl.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -642,7 +642,6 @@ static int opt_continue(opt_handler_params_t *args)
642642

643643
static int opt_status(opt_handler_params_t *args)
644644
{
645-
int retval = args->retval;
646645
if (*(args->count) > 3) {
647646
audit_msg(LOG_ERR,
648647
"Too many options for status command");
@@ -1189,15 +1188,14 @@ static int opt_mount(opt_handler_params_t *args)
11891188

11901189
static int opt_trim(opt_handler_params_t *args)
11911190
{
1192-
1193-
int retval = args->retval;
1194-
retval = audit_trim_subtrees(fd);
1191+
int retval = audit_trim_subtrees(fd);
11951192
if (retval <= 0)
11961193
retval = OPT_ERROR_NO_REPLY;
11971194
else {
11981195
args->finish = 1;
11991196
return OPT_SUCCESS_NO_REPLY; // success - no reply needed
12001197
}
1198+
return retval;
12011199
}
12021200

12031201
static int opt_version(opt_handler_params_t *args)

0 commit comments

Comments
 (0)