Re: Problem in using Kernel Timers: Sleeping function called from invalid context

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Ganesh PS wrote:
> I am not using kfree() for the task_struct *p variable because
> find_task_by_pid() returns a pointer to the PCB, so if i'll free the pointer
> then it frees that memory block and i am getting a segmentation fault.

I don't know about kernel timers, but...

First, you need read_lock(&tasklist_lock)
before calling find_task_by_pid(), see
http://lxr.linux.no/source/fs/fcntl.c?v=2.6.18#L480 for example.

Second, doing

p=kmalloc(sizeof(struct task_struct), GFP_KERNEL);
p=find_task_by_pid(pid);

will not copy the content of the task_struct of target process.
Thus, it is meaningless to call kmalloc() and
your code is nothing but leaking memory.

You can't kfree() the memory returned by find_task_by_pid(), for
the memory is not allocated by you using kmalloc().
It is allocated by alloc_task_struct(). You can trace it from
do_fork() at http://lxr.linux.no/source/kernel/fork.c?v=2.6.18#L1338 .

--
To unsubscribe from this list: send an email with
"unsubscribe kernelnewbies" to ecartis@xxxxxxxxxxxx
Please read the FAQ at http://kernelnewbies.org/FAQ


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux