2013-07-26 26 views
-1

我已经使用Sun编译器将使用Sun编译器的代码从Solaris/Sparc/x86移植到使用GCC 4.4.6的Red Hat Linux 6.2,并且在valgrind下的代码报告内存损坏方面存在问题和核心倾销。使用Linux进行共享库调用时HEAP损坏RHL 6.2

相同的源在Solaris上运行时没有错误,包括Sparc和x86。

发生错误的区域位于我打电话检索系统配置的共享库中。

它抱怨的内存是共享库中的本地堆栈变量。 Valgrind不帮我找到发生故障的实际区域。

带有“-d check -b -p 1”选项的DBGMEM内存调试程序未检测到任何可在报告中看到的内存,并且程序正常退出。

带有“-v --leak-check = yes --read-var-info = yes”选项的valgrind内存调试器失败,报告无效写入。

从Valgrind的日志:

==22043== Invalid write of size 8 
==22043== at 0x51DF74D: setLockingMode (db_support_funcs.c:258) 
==22043== by 0x40BF4E: GetAmaHdrParameters (AmaFileWriter.c:3707) 
==22043== by 0x40490E: MakeAMADNSFile (AmaFileWriter.c:899) 
==22043== by 0x403109: main (MakeAmaFile.c:775) 
==22043== Address 0x7fefebea8 is not stack'd, malloc'd or (recently) free'd 
==22043== 
==22043== Invalid write of size 8 
==22043== at 0x51DF348: logconfig (db_support_funcs.c:228) 
==22043== by 0x51DF790: setLockingMode (db_support_funcs.c:257) 
==22043== by 0x40BF4E: GetAmaHdrParameters (AmaFileWriter.c:3707) 
==22043== by 0x40490E: MakeAMADNSFile (AmaFileWriter.c:899) 
==22043== by 0x403109: main (MakeAmaFile.c:775) 
==22043== Address 0x7fefebd68 is not stack'd, malloc'd or (recently) free'd 
==22043== 
==22043== Invalid write of size 8 
==22043== at 0x51DF36A: logconfig (db_support_funcs.c:176) 
==22043== by 0x51DF790: setLockingMode (db_support_funcs.c:257) 
==22043== by 0x40BF4E: GetAmaHdrParameters (AmaFileWriter.c:3707) 
==22043== by 0x40490E: MakeAMADNSFile (AmaFileWriter.c:899) 
==22043== by 0x403109: main (MakeAmaFile.c:775) 
==22043== Address 0x7fefebcc8 is not stack'd, malloc'd or (recently) free'd 
==22043== 
==22043== Invalid write of size 8 
==22043== at 0x51DF396: logconfig (db_support_funcs.c:177) 
==22043== by 0x51DF790: setLockingMode (db_support_funcs.c:257) 
==22043== by 0x40BF4E: GetAmaHdrParameters (AmaFileWriter.c:3707) 
==22043== by 0x40490E: MakeAMADNSFile (AmaFileWriter.c:899) 
==22043== by 0x403109: main (MakeAmaFile.c:775) 
==22043== Address 0x7fefeacb8 is not stack'd, malloc'd or (recently) free'd 
==22043== 
==22043== 
==22043== Process terminating with default action of signal 11 (SIGSEGV): dumping core 
==22043== Access not within mapped region at address 0x7FEFEACB8 
==22043== at 0x51DF396: logconfig (db_support_funcs.c:177) 
==22043== by 0x51DF790: setLockingMode (db_support_funcs.c:257) 
==22043== by 0x40BF4E: GetAmaHdrParameters (AmaFileWriter.c:3707) 
==22043== by 0x40490E: MakeAMADNSFile (AmaFileWriter.c:899) 
==22043== by 0x403109: main (MakeAmaFile.c:775) 
==22043== If you believe this happened as a result of a stack 
==22043== overflow in your program's main thread (unlikely but 
==22043== possible), you can try to increase the size of the 
==22043== main thread stack using the --main-stacksize= flag. 
==22043== The main thread stack size used in this run was 10485760. 

是在db_support_funcs.c呼叫源的功能是:

-- line 255 -- void setLockingMode(short locking) 
-- line 256 -- { 
-- line 257 -- logconfig(0, LOG_DEBUG1, "DEBUG1:[%s:%d]:setLockingMode(locking=%d), currently %d", __FILE__,__LINE__, locking, disable_lock); 
-- line 258 -- disable_lock = locking; 
-- line 259 -- } 

-- line 168 -- void logconfig(int errnoflag, int level, const char *fmt, ...) 
-- line 169 -- { 
-- line 170 -- va_list  ap; 
-- line 171 -- int   errno_save = errno; /* Value caller might want printed */ 
-- line 172 -- long  n; 
-- line 173 -- time_t  curr_time; 
-- line 174 -- struct tm *curr_tm, 
-- line 175 --    *stat_tm; 
-- line 176 -- struct stat stat_buff; 
-- line 177 -- char  buff[BIG_BUFFER_LEN]; 
-- line 178 -- static char pid_str[MAX_PATH_LEN]; 
-- line 179 -- static int first_time = 1; 

编译代码与下列开关选择: 共享库: -D_LINUX_SOURCE -DLINUX -D_REENTRANT -DDEBUG_ENABLED -Wall -Wwrite-strings -DDEBUG -DTHREAD_SAFE -g -fstack-check -Wmissing-prototypes -Winterinter-arith -Wcast-align -DNOPROTX -pthread -D__LITTLE_ENDIAN = 1234 -D_LITTLEENDIAN -DL_ENDIAN -fPIC -DTHREAD_SAFE -shared -fPIC

应用: -D_LINUX_SOURCE -DLINUX -D_REENTRANT -DDEBUG_ENABLED -Wall -Wwrite串-DDEBUG -g -fstack检查-Wmissing的原型-Wpointer-ARITH -Wcast对齐-DNOPROTX - 并行线程-g -D__LITTLE_ENDIAN = 1234 -D_LITTLEENDIAN -DL_ENDIAN -fPIC

我用gcc 4.4.6版20110731(红帽4.4.6-3)(GCC)

回答

0

由于错误被报道多为日志函数的局部变量,我推断你的程序超出了线程的堆栈。该报告的底部提示,以这样的:

==22043== If you believe this happened as a result of a stack 
==22043== overflow in your program's main thread (unlikely but 
==22043== possible), you can try to increase the size of the 
==22043== main thread stack using the --main-stacksize= flag. 
==22043== The main thread stack size used in this run was 10485760. 

valgrind是使用10MB主线程堆栈。将此堆栈大小与valgrind错误报告中调用链中每个函数在堆栈中使用的预期内存进行比较。

+0

我已经尝试了4倍的堆栈大小作为快速检查和结果没有差异。 – user2623902

+0

== 29969 ==如果您认为这是因为堆栈的结果 == 29969 ==程序的主线程溢出(不太可能,但是 == 29969 ==可能),您可以尝试增加 == 29969 ==使用--main-stacksize =标志的主线程堆栈。 == 29969 ==此次运行中使用的主线程堆栈大小为41943040. – user2623902

+0

BIG_BUFFER_LEN有多大?在坠毁的那一刻,你没有给我预期的堆栈大小。 – jxh