Move free(cmd) to after last use of cmd in intel_gpu_top

Error: Use after free (CWE 416)
   Use after free of pointer 'cmd' in call to fprintf
        at line 496 of tools/intel_gpu_top.c in function 'main'.
          Previously freed at line 491 with free.
[ This bug was found by the Parfait 0.4.2 bug checking tool.
  For more information see http://labs.oracle.com/projects/parfait/ ]

Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
This commit is contained in:
Alan Coopersmith 2012-02-04 09:05:08 -08:00 committed by Daniel Vetter
parent 3d46ca8c4d
commit e61b917134

View File

@ -488,7 +488,6 @@ int main(int argc, char **argv)
else if (child_pid == 0) { else if (child_pid == 0) {
int res; int res;
res = system(cmd); res = system(cmd);
free(cmd);
if (res < 0) if (res < 0)
perror("running command"); perror("running command");
if (output) { if (output) {
@ -496,6 +495,7 @@ int main(int argc, char **argv)
fprintf(output, "# %s exited with status %d\n", cmd, res); fprintf(output, "# %s exited with status %d\n", cmd, res);
fflush(output); fflush(output);
} }
free(cmd);
exit(0); exit(0);
} else { } else {
free(cmd); free(cmd);