Добрый день, Есть вот такой тест кейс который переполняется, после 3х циклов нажатий F2,F3,F2,F3,F2,F3 программа растет в памяти. Использую ncurses. Код | //gcc -Wall -g3 tst.c -o tst -lmenu #include <stdlib.h> #include <stdarg.h> #include <string.h> #include <sys/types.h> #include <errno.h> #include <unistd.h> #include <signal.h> #include <wchar.h> #include <ncursesw/curses.h> #include <curses.h> #include <ncursesw/term.h> #include <term.h> #include <ncursesw/unctrl.h> #include <unctrl.h> #include <assert.h> #include <ctype.h> #include <locale.h> #include <sys/types.h> #include <sys/stat.h>
WINDOW **create_mwin(int k,int mwin){ int m,l; WINDOW **w; w = calloc(LINES-4,sizeof(WINDOW *));
w[0]=newwin(LINES-2,COLS,1,0); wbkgd(w[0],COLOR_PAIR(1)); box(w[0],ACS_VLINE,ACS_HLINE);
for (m=1,l=mwin;m<LINES-4;m++){ w[m] =subwin(w[0],1,COLS-2,m+1,1); }
wbkgd(w[1],COLOR_PAIR(6)); wrefresh(w[0]); return w; }
void delete_mwin(WINDOW **w,int count){ int i; for (i=0;i<count;i++){ werase(w[i]); delwin(w[i]); } free(w); }
int main(){ int key,quit=1,k=0,s=0;
WINDOW **mwin_w; static WINDOW *master;
setlocale(LC_ALL, "");
initscr(); cbreak(); noecho(); intrflush(stdscr, 0); keypad(stdscr, 1); if (has_colors()) { start_color(); init_pair(1, COLOR_WHITE, COLOR_BLACK); init_pair(6, COLOR_WHITE, COLOR_CYAN); bkgd(COLOR_PAIR(1)); }
master = newwin(1, COLS, LINES-1, 0);
while(quit){
key = getch(); switch(key) { case 266: // F2 mwin_w=create_mwin(k,s); break; case 267: // F3 delete_mwin(mwin_w,LINES-4); erase(); break; case 27: // ESCAPE quit=0; break; } refresh(); }
endwin();
exit(1); }
|
вот как я это нашел... Код | root 5598 0.0 0.0 16064 1152 pts/0 S+ 02:13 0:00 ./tst root 5598 0.0 0.0 16196 1416 pts/0 S+ 02:13 0:00 ./tst root 5598 0.0 0.0 16460 1680 pts/0 S+ 02:13 0:00 ./tst
|
в valgrind тоже не все гладко, куча непочищенной памяти после каждого нажатия F2 её больше. Код | ==5598== LEAK SUMMARY: ==5598== definitely lost: 0 bytes in 0 blocks ==5598== indirectly lost: 0 bytes in 0 blocks ==5598== possibly lost: 0 bytes in 0 blocks ==5598== still reachable: 360,902 bytes in 484 blocks ==5598== suppressed: 0 bytes in 0 blocks ==5598== Rerun with --leak-check=full to see details of leaked memory ==5598== ==5598== Use --track-origins=yes to see where uninitialised values come from ==5598== ERROR SUMMARY: 4 errors from 3 contexts (suppressed: 0 from 0) ==5598== ==5598== 1 errors in context 1 of 3: ==5598== Conditional jump or move depends on uninitialised value(s) ==5598== at 0x40178FB: index (in /lib64/ld-2.16.so) ==5598== by 0x4007552: expand_dynamic_string_token (in /lib64/ld-2.16.so) ==5598== by 0x4007E2D: _dl_map_object (in /lib64/ld-2.16.so) ==5598== by 0x400136D: map_doit (in /lib64/ld-2.16.so) ==5598== by 0x400E235: _dl_catch_error (in /lib64/ld-2.16.so) ==5598== by 0x4001286: do_preload (in /lib64/ld-2.16.so) ==5598== by 0x4003995: dl_main (in /lib64/ld-2.16.so) ==5598== by 0x4014937: _dl_sysdep_start (in /lib64/ld-2.16.so) ==5598== by 0x400487C: _dl_start (in /lib64/ld-2.16.so) ==5598== by 0x4000BA7: ??? (in /lib64/ld-2.16.so)
|
|