SegFault Irgendwann



  • Hallo,

    Mein Programm läuft eigentlich stabil durch, jedoch nach einer Zeit von 5-10 Minuten bekommt es einfach einen SegFault.
    Ich hab hier mal valgrind laufen lassen und habe mich gefragt, ob Ihr den Output eventuel analysieren könnt, ich hab mit valegrind noch nie wirklich was gemacht.

    ==20858== Warning: invalid file descriptor 1019 in syscall open()
    ==20858== Invalid read of size 2
    ==20858== at 0x4090128: fputs (in /lib/tls/i686/cmov/libc-2.7.so)
    ==20858== by 0x8048D7F: write_file (io.h:39)
    ==20858== by 0x80493E5: read_dir (sis.c:225)
    ==20858== by 0x8049BE7: main (sis.c:291)
    ==20858== Address 0x0 is not stack'd, malloc'd or (recently) free'd
    ==20858==
    ==20858== Process terminating with default action of signal 11 (SIGSEGV)
    ==20858== Access not within mapped region at address 0x0
    ==20858== at 0x4090128: fputs (in /lib/tls/i686/cmov/libc-2.7.so)
    ==20858== by 0x8048D7F: write_file (io.h:39)
    ==20858== by 0x80493E5: read_dir (sis.c:225)
    ==20858== by 0x8049BE7: main (sis.c:291)
    ==20858==
    ==20858== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 11 from 1)
    ==20858== malloc/free: in use at exit: 3,164,062 bytes in 1,521 blocks.
    ==20858== malloc/free: 5,795 allocs, 4,274 frees, 4,668,510 bytes allocated.
    ==20858== For counts of detected errors, rerun with: -v
    ==20858== searching for pointers to 1,521 not-freed blocks.
    ==20858== checked 1,310,360 bytes.
    ==20858==
    ==20858== LEAK SUMMARY:
    ==20858== definitely lost: 3,150,504 bytes in 1,512 blocks.
    ==20858== possibly lost: 8,240 bytes in 2 blocks.
    ==20858== still reachable: 5,318 bytes in 7 blocks.
    ==20858== suppressed: 0 bytes in 0 blocks.
    ==20858== Rerun with --leak-check=full to see details of leaked memory.
    Segmentation fault

    Danke für eure Infos



  • Hier habe ich valegrind mit dem -V Parameter laufen lassen:

    ==23094== Warning: invalid file descriptor 1019 in syscall open()
    ==23094== at 0x40007F2: (within /lib/ld-2.7.so)
    ==23094== by 0x409B372: _IO_file_fopen (in /lib/tls/i686/cmov/libc-2.7.so)
    ==23094== by 0x408FD9C: (within /lib/tls/i686/cmov/libc-2.7.so)
    ==23094== by 0x408FDFB: fopen (in /lib/tls/i686/cmov/libc-2.7.so)
    ==23094== by 0x8048D71: write_file (io.h:38)
    ==23094== by 0x80493E5: read_dir (sis.c:225)
    ==23094== by 0x8049BE7: main (sis.c:291)
    ==23094== Invalid read of size 2
    ==23094== at 0x4090128: fputs (in /lib/tls/i686/cmov/libc-2.7.so)
    ==23094== by 0x8048D7F: write_file (io.h:39)
    ==23094== by 0x80493E5: read_dir (sis.c:225)
    ==23094== by 0x8049BE7: main (sis.c:291)
    ==23094== Address 0x0 is not stack'd, malloc'd or (recently) free'd
    ==23094==
    ==23094== Process terminating with default action of signal 11 (SIGSEGV)
    ==23094== Access not within mapped region at address 0x0
    ==23094== at 0x4090128: fputs (in /lib/tls/i686/cmov/libc-2.7.so)
    ==23094== by 0x8048D7F: write_file (io.h:39)
    ==23094== by 0x80493E5: read_dir (sis.c:225)
    ==23094== by 0x8049BE7: main (sis.c:291)
    ==23094==
    ==23094== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 11 from 1)
    ==23094==
    ==23094== 1 errors in context 1 of 1:
    ==23094== Invalid read of size 2
    ==23094== at 0x4090128: fputs (in /lib/tls/i686/cmov/libc-2.7.so)
    ==23094== by 0x8048D7F: write_file (io.h:39)
    ==23094== by 0x80493E5: read_dir (sis.c:225)
    ==23094== by 0x8049BE7: main (sis.c:291)
    ==23094== Address 0x0 is not stack'd, malloc'd or (recently) free'd
    --23094--
    --23094-- supp: 11 dl-hack3-1
    ==23094==
    ==23094== IN SUMMARY: 1 errors from 1 contexts (suppressed: 11 from 1)
    ==23094==
    ==23094== malloc/free: in use at exit: 3,151,560 bytes in 1,515 blocks.
    ==23094== malloc/free: 5,796 allocs, 4,281 frees, 4,658,472 bytes allocated.
    ==23094==
    ==23094== searching for pointers to 1,515 not-freed blocks.
    ==23094== checked 1,310,196 bytes.
    ==23094==
    ==23094== LEAK SUMMARY:
    ==23094== definitely lost: 3,146,242 bytes in 1,508 blocks.
    ==23094== possibly lost: 0 bytes in 0 blocks.
    ==23094== still reachable: 5,318 bytes in 7 blocks.
    ==23094== suppressed: 0 bytes in 0 blocks.
    ==23094== Rerun with --leak-check=full to see details of leaked memory.
    --23094-- memcheck: sanity checks: 3494 cheap, 65 expensive
    --23094-- memcheck: auxmaps: 0 auxmap entries (0k, 0M) in use
    --23094-- memcheck: auxmaps_L1: 0 searches, 0 cmps, ratio 0:10
    --23094-- memcheck: auxmaps_L2: 0 searches, 0 nodes
    --23094-- memcheck: SMs: n_issued = 97 (1552k, 1M)
    --23094-- memcheck: SMs: n_deissued = 0 (0k, 0M)
    --23094-- memcheck: SMs: max_noaccess = 65535 (1048560k, 1023M)
    --23094-- memcheck: SMs: max_undefined = 0 (0k, 0M)
    --23094-- memcheck: SMs: max_defined = 39 (624k, 0M)
    --23094-- memcheck: SMs: max_non_DSM = 97 (1552k, 1M)
    --23094-- memcheck: max sec V bit nodes: 0 (0k, 0M)
    --23094-- memcheck: set_sec_vbits8 calls: 0 (new: 0, updates: 0)
    --23094-- memcheck: max shadow mem size: 1856k, 1M
    --23094-- translate: fast SP updates identified: 2,673 ( 89.6%)
    --23094-- translate: generic_known SP updates identified: 194 ( 6.5%)
    --23094-- translate: generic_unknown SP updates identified: 115 ( 3.8%)
    --23094-- tt/tc: 16,454 tt lookups requiring 16,577 probes
    --23094-- tt/tc: 16,454 fast-cache updates, 2 flushes
    --23094-- transtab: new 2,634 (55,901 -> 804,136; ratio 143:10) [0 scs]
    --23094-- transtab: dumped 0 (0 -> ??)
    --23094-- transtab: discarded 0 (0 -> ??)
    --23094-- scheduler: 349,405,274 jumps (bb entries).
    --23094-- scheduler: 3,494/59,474 major/minor sched events.
    --23094-- sanity: 3495 cheap, 65 expensive checks.
    --23094-- exectx: 769 lists, 26 contexts (avg 0 per list)
    --23094-- exectx: 10,089 searches, 10,063 full compares (997 per 1000)
    --23094-- exectx: 0 cmp2, 26 cmp4, 0 cmpAll
    --23094-- errormgr: 7 supplist searches, 145 comparisons during search
    --23094-- errormgr: 12 errlist searches, 32 comparisons during search
    Segmentation fault



  • Hast Du Dir den Dump auch mal durchgelesen oder ihn nur hierhin gepostet?!

    ==23094== Warning: invalid file descriptor 1019 in syscall open()
    [...]
    ==23094== by 0x8048D71: write_file (io.h:38)

    ==23094== Access not within mapped region at address 0x0
    [...]
    ==23094== by 0x8048D7F: write_file (io.h:39)



  • Ah danke 🙂
    Muss ich wohl überlesen haben, mein Fehler.

    Meine write Funktion sieht aber so aus, also meiner Meinung nach in Ordnung:

    int write_file (char* filename, char* text)
    {
    	FILE* f = fopen (filename, "a");
    	fputs (text, f);
    	fputs ("\n", f);
    	fclose(f);
    }
    

    Oder überseh ich da was?
    Danke 🙂



  • gibts das file?



  • Die Datei existiert und es wird auch in die Datei geschrieben.
    Nur auf einmal gibts eben den SegFault...



  • segfault25 schrieb:

    Ah danke 🙂
    Muss ich wohl überlesen haben, mein Fehler.

    Meine write Funktion sieht aber so aus, also meiner Meinung nach in Ordnung:

    int write_file (char* filename, char* text)
    {
    	FILE* f = fopen (filename, "a");
    	fputs (text, f);
    	fputs ("\n", f);
    	fclose(f);
    }
    

    Oder überseh ich da was?
    Danke 🙂

    eine int Funktion sollte immer einen Wert zurüchgeben. Außerdem kann fopen auf NULL zurückgeben und dann kracht das Programm.

    int write_file (char* filename, char* text)
    {
        FILE* f = fopen (filename, "a");
    
        if(f == NULL) {
            fprintf(stderr, "Could not open %s\n", filename);
            return 0;
        }
    
        fputs (text, f);
        fputs ("\n", f);
        fclose(f);
        return 1;
    }
    


  • Hallo,

    Danke für die Antwort.
    Werde es sofort ausprobieren 🙂



  • Ich habs versucht!
    Es funktioniert ABER:
    Mein Programm ist darauf angewiesen, dass diese fopen FUnktionen funktionieren. Sprich nach einer Zeit kommt jetzt der Fehler:
    "could not open "%s filename

    Aber ich würde gerne, dass mein Programm da weitermacht?
    Bzw. warum passiert dieser Fehler?
    Gibt es alternative, sichere Funktionen?
    Was könnte ich noch machen?

    Danke für die Hilfe


Anmelden zum Antworten