Skip to content

Commit

Permalink
Fix memhog uses the wrong policy but still works properly
Browse files Browse the repository at this point in the history
`memhog 1G memb` can work, it will cause misunderstanding.
 When the parameter is incorrect, Now it directly use the
last assignment of p, "default".After the fixed, the usage
will be displayed in this case.
  • Loading branch information
luochunsheng authored and andikleen committed Aug 25, 2022
1 parent 4b4e31d commit 1de4ad7
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions util.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,16 +111,20 @@ int parse_policy(char *name, char *arg)
{
int k;
struct policy *p = NULL;
int found = 0;

if (!name)
return MPOL_DEFAULT;

while (*name == '-') name++;
for (k = 0; policies[k].name; k++) {
p = &policies[k];
if (!strcmp(p->name, name))
if (!strcmp(p->name, name)) {
found = 1;
break;
}
}
if (!p || !p->name || (!arg && !p->noarg))
if (!found || !p || !p->name || (!arg && !p->noarg))
return MPOL_MAX;
return p->policy;
}
Expand Down

0 comments on commit 1de4ad7

Please sign in to comment.