Skip to content

Commit

Permalink
Check if fix_prop is NULL before allocating orig_prop
Browse files Browse the repository at this point in the history
This is so that we don't even have to bother calling strdup if the first malloc fails, and if the strdup fails, we only free fix_prop.
  • Loading branch information
AreaZR committed Jul 16, 2023
1 parent 20b768f commit f2e5ffd
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions match.c
Original file line number Diff line number Diff line change
Expand Up @@ -321,13 +321,17 @@ static char *
filter_list(const char *proposal, const char *filter, int denylist)
{
size_t len = strlen(proposal) + 1;
char *fix_prop = malloc(len);
char *orig_prop = strdup(proposal);
char *orig_prop, *fix_prop;
char *cp, *tmp;
int r;

if (fix_prop == NULL || orig_prop == NULL) {
free(orig_prop);
fix_prop = malloc(len);
if (fix_prop == NULL) {
return NULL;
}

orig_prop = strdup(proposal);
if (orig_prop == NULL) {
free(fix_prop);
return NULL;
}
Expand Down

0 comments on commit f2e5ffd

Please sign in to comment.