[cfe-dev] valgrind error
Benoit Boissinot
bboissin+llvm at gmail.com
Wed Jul 18 23:17:44 PDT 2007
I get the following errors with valgrind (and some leaks but I haven't
resolved them yet)
==4810== Invalid write of size 4
==4810== at 0x81BCE8A: clang::QualType::QualType() (Type.h:59)
==4810== by 0x820289A: clang::FunctionTypeProto::FunctionTypeProto(clang::QualType, clang::QualType*, unsigned, bool, clang::QualType) (Type.h:565)
[snip]
==4810== Address 0x42CFD10 is 0 bytes after a block of size 24 alloc'd
==4810== at 0x4021620: malloc (vg_replace_malloc.c:149)
==4810== by 0x81FF7C1: clang::ASTContext::getFunctionType(clang::QualType, clang::QualType*, unsigned, bool) (ASTContext.cpp:550)
[snip]
The following patch fixes it:
(it only removes 1 sizeof(QualType) if NumArgs is > 0)
If you prefer to avoid !!NumArgs (it is quite common in the linux kernel for
example, but it may be seen as an obfuscation by some people), I could use
(NumArgs ? 1 : 0)
--- AST/ASTContext.cpp (revision 40015)
+++ AST/ASTContext.cpp (working copy)
@@ -547,7 +547,7 @@
// variable size array (for parameter types) at the end of them.
FunctionTypeProto *FTP =
(FunctionTypeProto*)malloc(sizeof(FunctionTypeProto) +
- (NumArgs-1)*sizeof(QualType));
+ (NumArgs-!!NumArgs)*sizeof(QualType));
new (FTP) FunctionTypeProto(ResultTy, ArgArray, NumArgs, isVariadic,
Canonical);
Types.push_back(FTP);
--
:wq
-------------- next part --------------
A non-text attachment was scrubbed...
Name: fix_valgrind.diff
Type: text/x-diff
Size: 624 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20070719/9cd6179d/attachment.diff>
More information about the cfe-dev
mailing list