Hi LLVM developers,
I have taught the analyzer about Glib API to check Memory-leak issue, please review my patch, thanks a lot!
Regards,
Leslie Zhai
Differential D28348
[analyzer] Taught the analyzer about Glib API to check Memory-leak xiangzhai on Jan 5 2017, 1:08 AM. Authored by
Details Hi LLVM developers, I have taught the analyzer about Glib API to check Memory-leak issue, please review my patch, thanks a lot! Regards,
Diff Detail
Event TimelineComment Actions Thanks for the patch! Could you, please, resubmit the patch with context as described here http://llvm.org/docs/Phabricator.html Comment Actions Hi Anna, Thanks for your review! I resubmit the patch with context, please check is it correct, thanks a lot! Comment Actions Phabricator still says that context is not available. Please, pass -U9999 when generating the patch. Thanks!
Comment Actions Hi Anna, Thanks for your review! I use: svn diff --diff-cmd=diff -x -U999999 lib/StaticAnalyzer/Checkers/MallocChecker.cpp test/Analysis/gmalloc.c > Glib-MallocChecker.patch to generate the patch, please check is it correct. And I run: clang -cc1 -analyze -analyzer-checker=core,unix.Malloc -analyzer-store=region -verify gmalloc.c There is *NO* issue, please check it, thanks a lot! Regards,
Comment Actions Hi Anna, Thanks for your review! I process them (for example, g_malloc_n, take a different number of arguments) separately. And I run the testcases for Analysis/malloc.c and Analysis/gmalloc.c Regards,
Comment Actions Hi Anna, Thank you so much for the review! I will try to implement extend MallocMemAux and ReallocMem in the follow up patch. Regards,
Comment Actions Hi Anna, I am not clear why need to calculate the precise allocated size? For example: void *ptr = malloc(size); void *gptr = g_malloc_n(n_blocks, n_block_bytes); Memory-leak and Use-after-free issues' MallocChecker need the *size* or *n_blocks* x *n_block_bytes*, but if the size is inaccurate, the checker is also *able* to detect the issues https://bugzilla.gnome.org/show_bug.cgi?id=777077 Regards,
Comment Actions Hi Anna, I added svalBinMulOp to take BO_Mul evalBinOp for g_malloc_n's two arguments: State->getSVal(CE->getArg(0), C.getLocationContext()) MUL State->getSVal(CE->getArg(1), C.getLocationContext()), so it does NOT need to change MallocMemAux any more, but just use it in this way: State = MallocMemAux(C, CE, svalBinMulOp(C, State->getSVal(CE->getArg(0), C.getLocationContext()), State->getSVal(CE->getArg(1), C.getLocationContext()), State), UndefinedVal(), State); And I also added ReallocMemN for g_realloc_n, it also use svalBinMulOp for !StateSizeIsZero check. Please indicate my mistake, thanks a lot! Regards, Comment Actions Fixed the confused State->getSVal(CE->getArg(1), C.getLocationContext()); with CE->getArg(1) issue. Comment Actions Could you please split the patch into two - one with the previously reviewed support for functions that take a single size value and another patch that models the two size arguments (num and size). It's easier to review patches if they do not grow new functionality. Splitting the patch would also play nicely with the incremental development policy of LLVM. Thanks! Comment Actions Hi Anna, Thanks for your suggest! Firstly I uploaded Glib-MallocChecker-single-size-value.patch for code review, if submitted to UPSTREAM, then upload another one, correct? Regards, Comment Actions
Yes. By the way, you can model XXX_n variants similarly to how calloc is modeled (see CallocMem).
Comment Actions Hi Anna, Thanks for your review! I updated the Glib-MallocChecker-single-size-value.patch to use zeroVal for g_malloc0 and g_try_malloc0 and Yes, I refer CallocMem to implement SValBinMulOp in the Glib-MallocChecker-all-in-one.patch if Glib-MallocChecker-single-size-value.patch could be submitted to UPSTREAM, then I create another patch for XXX_n, thanks for your suggest! Regards, Comment Actions
The information generated by this checker is used for array bounds checking. For example, see https://reviews.llvm.org/D24307 This patch looks good. Do you have commit access or should I commit it on your behalf? Comment Actions Hi Anna, Thanks for your review!
I will read carefully about that ;-)
Please commit it on my behalf, thanks a lot! Regards, |