Skip to content

Commit

Permalink
sched_setparam/9-1: cleanup code and fix memory leak
Browse files Browse the repository at this point in the history
1) add a parameter for kill_children() and replace
   the for-loop(s) of kill() with it.

2) free the memory after killing children process.

Signed-off-by: Wei,Jiangang <[email protected]>
Signed-off-by: Cyril Hrubis <[email protected]>
  • Loading branch information
PandaWei authored and metan-ucw committed Jun 3, 2015
1 parent 9e2011c commit 5b5ca55
Showing 1 changed file with 9 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -131,17 +131,18 @@ static void test_process(void)
pause();
}

static void kill_children(int *child_pid)
static void kill_children(int *child_pid, int count)
{
int i;

for (i = 0; i < nb_cpu; i++)
for (i = 0; i < count; i++)
kill(child_pid[i], SIGTERM);
free(child_pid);
}

int main(void)
{
int *child_pid, oldcount, newcount, shm_id, i, j;
int *child_pid, oldcount, newcount, shm_id, i;
struct sched_param param;
key_t key;
int rc = set_affinity(0);
Expand Down Expand Up @@ -191,9 +192,7 @@ int main(void)
child_pid[i] = fork();
if (child_pid[i] == -1) {
perror("An error occurs when calling fork()");
for (j = 0; j < i; j++)
kill(child_pid[j], SIGTERM);

kill_children(child_pid, i);
return PTS_UNRESOLVED;
} else if (child_pid[i] == 0) {

Expand All @@ -207,9 +206,7 @@ int main(void)
child_pid[i] = fork();
if (child_pid[i] == -1) {
perror("An error occurs when calling fork()");
for (j = 0; j < i; j++)
kill(child_pid[j], SIGTERM);

kill_children(child_pid, i);
return PTS_UNRESOLVED;
} else if (child_pid[i] == 0) {

Expand All @@ -223,19 +220,19 @@ int main(void)
oldcount = *shmptr;
if (sched_setparam(child_pid[i], &param) != 0) {
perror("An error occurs when calling sched_setparam()");
kill_children(child_pid);
kill_children(child_pid, nb_cpu);
return PTS_UNRESOLVED;
}
newcount = *shmptr;

if (newcount == oldcount) {
printf("The target process does not preempt"
" the calling process\n");
kill_children(child_pid);
kill_children(child_pid, nb_cpu);
return PTS_FAIL;
}

printf("Test PASSED\n");
kill_children(child_pid);
kill_children(child_pid, nb_cpu);
return PTS_PASS;
}

0 comments on commit 5b5ca55

Please sign in to comment.