Module Name: src Committed By: christos Date: Fri Dec 30 20:33:04 UTC 2011
Modified Files: src/sys/kern: kern_ktrace.c Log Message: Avoid panic on DIAGNOSTIC kernels with ktrace -p <not-existing-process> The old logic was: error = ktrace_common(, fp); if (fp) if (error) fd_abort(, fp, ); else fd_abort(, NULL, ); The 'if (fp)' portion really means if the op is not KTROP_CLEAR, since the logic above always sets up fp otherwise, so change the code to test this directly. ktrace_common() can return an error both on the kernel thread creation failure, which means that we should be calling fd_abort() with fp, since nobody used the file yet and we should clear it now. But it can also return an error because later, after the thread creation if the process or process group was not found. In this second case, we should be calling fd_abort with NULL, since the fp is now used by the thread and it is going to clean it later. So instead of checking the error from ktrace_common() to decide if we are going to call fd_abort() with a NULL fp or not, let krace_common() decide for us. So the new logic becomes: error = ktrace_common(, &fp); if (op != KTROP_CLEAR) fd_abort(, fp, ); Since I am here, fix a freed memory access, by setting ktd to FALSE. To generate a diff of this commit: cvs rdiff -u -r1.159 -r1.160 src/sys/kern/kern_ktrace.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.