Valgrind показывает утечку даже после операции удаления - PullRequest
1 голос
/ 07 июня 2019

У меня очень простая программа:

#include<iostream>
using namespace std;

int main()
{
        char *s=new char[10];
        cin>>s;
        cout<<s;
        delete[] s;
}

Я не могу понять, что я могу сделать для Вальгринда, чтобы не жаловаться на это:

==5139== LEAK SUMMARY:
==5139==    definitely lost: 32 bytes in 1 blocks
==5139==    indirectly lost: 24 bytes in 1 blocks
==5139==      possibly lost: 0 bytes in 0 blocks
==5139==    still reachable: 31,451 bytes in 759 blocks

РЕДАКТИРОВАТЬ 2: Добавление ошибки Valgrind / сводный отчет по куче:

==42891== LEAK SUMMARY:
==42891==    definitely lost: 20 bytes in 1 blocks
==42891==    indirectly lost: 0 bytes in 0 blocks
==42891==      possibly lost: 0 bytes in 0 blocks
==42891==    still reachable: 528,598 bytes in 11,121 blocks
==42891==         suppressed: 0 bytes in 0 blocks
==42891== Rerun with --leak-check=full to see details of leaked memory
==42891==
==42891== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
==42891== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
--42890-- REDIR: 0x52ead60 (libc.so.6:__GI_stpcpy) redirected to 0x4c2d8d0 (__GI_stpcpy)
--42890-- REDIR: 0x52e7590 (libc.so.6:__GI_strcpy) redirected to 0x4c2ab90 (__GI_strcpy)
--42890-- REDIR: 0x52e1450 (libc.so.6:realloc) redirected to 0x4c29aae (realloc)
--42890-- REDIR: 0x52eaf20 (libc.so.6:__GI___strcasecmp_l) redirected to 0x4c2b710 (__GI___strcasecmp_l)
test4.cpp: line 4: syntax error near unexpected token `('
test4.cpp: line 4: `int main()'
==42890==
==42890== HEAP SUMMARY:
==42890==     in use at exit: 528,567 bytes in 11,123 blocks
==42890==   total heap usage: 11,374 allocs, 251 frees, 570,897 bytes allocated
==42890==
==42890== Searching for pointers to 11,123 not-freed blocks
==42890== Checked 768,632 bytes
==42890==
==42890== LEAK SUMMARY:
==42890==    definitely lost: 32 bytes in 1 blocks
==42890==    indirectly lost: 24 bytes in 1 blocks
==42890==      possibly lost: 0 bytes in 0 blocks
==42890==    still reachable: 528,511 bytes in 11,121 blocks
==42890==         suppressed: 0 bytes in 0 blocks
==42890== Rerun with --leak-check=full to see details of leaked memory
==42890==
==42890== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
==42890== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)

g ++ (GCC) 4.8.5 20150623 (Red Hat 4.8.5-11)

valgrind - версия
Valgrind-3.11.0

...