문제

==11136== Invalid read of size 8
==11136==    at 0x5AFC696: memrchr (memrchr.S:289)
==11136==    by 0x5B57FAF: dirname (dirname.c:45)
==11136==    by 0x405F43: push::lg_cmd_dirname(push::Env&) (LGExtension.cpp:379)
==11136==    by 0x42533C: push::Instruction::operator()(push::Env&) const (in /home/bots/svn/eco/branches/skynet_BigPUSH/src/push3.0/extension/push_bloodline)
==11136==    by 0x488ECD: push::Env::go(int) (Env.cpp:72)
==11136==    by 0x4A84D5: main (bloodline.cpp:99)
==11136==  Address 0x640daf8 is 8 bytes inside a block of size 10 alloc'd
==11136==    at 0x4C2B6CD: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==11136==    by 0x5AEF801: strdup (strdup.c:43)
==11136==    by 0x405EF2: push::lg_cmd_dirname(push::Env&) (LGExtension.cpp:369)
==11136==    by 0x42533C: push::Instruction::operator()(push::Env&) const (in /home/bots/svn/eco/branches/skynet_BigPUSH/src/push3.0/extension/push_bloodline)
==11136==    by 0x488ECD: push::Env::go(int) (Env.cpp:72)
==11136==    by 0x4A84D5: main (bloodline.cpp:99)
==11136==
.

이는 합법적 인 오류입니까?그것은 유효한 블록 내에 읽기가 일어나는 것처럼 보입니다.내 프로그램에서 전화는 다음과 같습니다.

        char *path = strdup(full_path.c_str());
        cerr << "Path is : " << path << endl;
        result = dirname(path);
        if(result < 0){
                cerr << "Dirname failed for some reason. Check log." << endl;
        }
.

및 오류시에 cerr 로의 출력은 다음과 같습니다.

Path is : /tmp/tmp/
. 유효한 경로 인

.dirname은 이것을 가지고 아무런 문제가 없어야하며, 힙으로 할당 된 힙에서 작동합니다.

편집 :

이 오류를 생성 할 최소한의 예가 있습니다 :

#include <string.h>
#include <stdio.h>
#include <iostream>
#include <libgen.h>

int main(){

        char *path = strdup("/tmp/tmp/");
        char* result = dirname(path);
        std::cerr << result << std::endl;
}
.

g ++로 컴파일하십시오.

valgrind로 실행하고 얻을 수 있습니다 :

==32466== Memcheck, a memory error detector                                                                                                                                                                                                  
==32466== Copyright (C) 2002-2011, and GNU GPL'd, by Julian Seward et al.                                                                                                                                                                    
==32466== Using Valgrind-3.7.0 and LibVEX; rerun with -h for copyright info                                                                                                                                                                  
==32466== Command: ./a.out                                                                                                                                                                                                                   
==32466==                                                                                                                                                                                                                                    
==32466== Invalid read of size 8                                                                                                                                                                                                             
==32466==    at 0x51C7696: memrchr (memrchr.S:289)                                                                                                                                                                                           
==32466==    by 0x5222FAF: dirname (dirname.c:45)                                                                                                                                                                                            
==32466==    by 0x400865: main (in /home/j3doucet/a.out)                                                                                                                                                                                     
==32466==  Address 0x59ff048 is 8 bytes inside a block of size 10 alloc'd                                                                                                                                                                    
==32466==    at 0x4C2B6CD: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)                                                                                                                                                   
==32466==    by 0x51BA801: strdup (strdup.c:43)                                                                                                                                                                                              
==32466==    by 0x400855: main (in /home/j3doucet/a.out)                                                                                                                                                                                     
==32466==                                                                                                                                                                                                                                    
/tmp
==32466== 
==32466== HEAP SUMMARY:
==32466==     in use at exit: 10 bytes in 1 blocks
==32466==   total heap usage: 1 allocs, 0 frees, 10 bytes allocated
==32466== 
==32466== LEAK SUMMARY:
==32466==    definitely lost: 10 bytes in 1 blocks
==32466==    indirectly lost: 0 bytes in 0 blocks
==32466==      possibly lost: 0 bytes in 0 blocks
==32466==    still reachable: 0 bytes in 0 blocks
==32466==         suppressed: 0 bytes in 0 blocks
==32466== Rerun with --leak-check=full to see details of leaked memory
==32466== 
==32466== For counts of detected and suppressed errors, rerun with: -v
==32466== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 2 from 2)
.

도움이 되었습니까?

해결책

valgrind는 바이트 NR 8에서 크기가 읽는 크기 8이 수행되었음을 나타냅니다. 10 바이트의 블록. 이 읽기는 memrchr에 의해 수행됩니다. 이러한 기능은 종종 읽을 수있는 가정에 따라 최적화됩니다. 할당 된 블록보다 많은 바이트. 이러한 문제를보고하지 않으려면 Valgrind는 이러한 최적화 된 것으로 대체해야합니다. 자체 재정의 기능으로 기능합니다.

memrchr은 버전 3.8 이후의 Valgrind에서만 재정의되었습니다.

=> 최신 버전의 Valgrind (3.8.1)로 다시 시도해야합니다. 오류는 더 이상보고되지 않을 수 있습니다 (효과적으로 잘못된 긍정적 인 것으로 가정합니다. MEMRCHR의 비 재정의로 인해).

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top