chrsmithdemos / leveldb

Automatically exported from code.google.com/p/leveldb
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

valgrind errors with leveldb while using heap or stack based struct variables #211

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. I am using a struct as a value to leveldb
2. I initialize this struct completely and pass it to leveldb batch write.
3. When you run this program through valgrind, you will notice an error stating 
"Use of uninitialised value of size 8"

I am have attached the complete program and valgrind error report to this issue 
for analysis.

In my program when I used the "wcData" either as local variable or local 
pointer getting allocated from heap, I get the same error. The errors go away 
when I make it a global variable. However that is not really an option in our 
eventual multhtreaded system.

Is it any genuine error to be worried about on which the system can eventually 
choke durin leveldb compaction, tcmalloc garbage collection etc.?

What is the expected output? What do you see instead?

I do not expect any valgrind error from this simple program.

What version of the product are you using? On what operating system?

I am using leveldb version 1.10 on ubuntu 12.0.4

Please provide any additional information below.

I have attached the complete program listing and valgrind error report below.

Original issue reported on code.google.com by sameer.s...@gmail.com on 23 Oct 2013 at 5:50

Attachments:

GoogleCodeExporter commented 9 years ago
This is not an error in LevelDB.  Your struct has extra padding in it that is 
not initialized in the constructor.  See the attached file for details.  Notice 
that the members of WCData consume 19B total, but WCData is 24B.

You can eliminate the error by rearranging your struct to not waste space, 
using memset(this, 0, sizeof(WCData)) if WCData is a POD type, or by explicitly 
telling valgrind to ignore this harmless uninitialized data.

What you should probably do is serialize the WCData struct into a 
compiler/byte-order independent format and store serialized strings instead of 
the struct itself.

Original comment by res...@gmail.com on 23 Oct 2013 at 11:09

Attachments:

GoogleCodeExporter commented 9 years ago
hhhmm... thanks for your response. I was trying the memset however I guess I 
didn't fully realize that my struct is not a compact POD...

Original comment by sameer.s...@gmail.com on 23 Oct 2013 at 11:39