Skip to content

Commit

Permalink
Check the results of fix_prop before allocating orig_pop
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 5, 2023
1 parent a95fc5e commit 981b2d3
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 981b2d3

Please sign in to comment.