weird error

This is a discussion on weird error within the Linux Programming forums, part of the Platform Specific Boards category; Hi, I develop program to change wallpaper in Gnome desktop. The program is simple but depend on three or four ...

  1. #1
    Registered User gandalf_bar's Avatar
    Join Date
    Oct 2003
    Posts
    92

    weird error

    Hi,

    I develop program to change wallpaper in Gnome desktop. The program is simple but depend on three or four uncommon library. So it does not make sense if I post my program here. This was the source code:
    Code:
    char* arg_list[7];
    
        arg_list[0] = new char[12];
        arg_list[1] = new char[3];
        arg_list[2] = new char[7];
        arg_list[3] = new char[3];
        arg_list[4] = new char[43];
        arg_list[6] = NULL;
    ...........
    
    //my program is daemon so it runs forever ( yeah, until you control break )
    while(true) 
    	{
                //do this every second
    	    sleep( 1 );
    
                //you know, Gnome desktop has more than one workspace/virtual desktop
                //this is checking where are we now?
                plot = popen("xprop -root _NET_CURRENT_DESKTOP", "r");
                if(plot!=NULL) 
    	    {
                    fread(accept, sizeof(char), 35, plot);
                    pclose(plot);
                }
    
    	    //todo: usee sstream to convert string to int
                chars_read = accept[33] - '0';
    
                //arg_list[5] is pointer, wallpaper is vector string containing path to wallpaper
    	    arg_list[5] = new char[ wallpaper[ chars_read ].at( number[ chars_read ] ).length() ];
    	    strcpy(arg_list[5],wallpaper[chars_read].at(number[chars_read]).c_str());
    
    	    //change the wallpaper using forking
    	    pro.spawn("gconftool-2", arg_list, 1);
    
    	    delete []arg_list[5];
    
            }
    Using this source code, my program crash using certain wallpaper path with weird error. I means, my program will ( always ) crash if it encounter with certain wallpaper ( maybe "/mnt/data/wallpaper/Dodo.jpg" ). So it will crash if it change the wallpaper to "/mnt/data/wallpaper/Dodo.jpg" but not with other wallpaper path. But if I run it with valgrind, it runs fine. Always runs fine. So I decided to change the source code. Here is the change:
    Code:
        //more than enough
        arg_list[5] = new char[1000];
    
        //I comment this 
        //arg_list[5] = new char[ wallpaper[ chars_read ].at( number[ chars_read ] ).length() ];
    
        //and this
        //delete []arg_list[5];
    Now my program never crash. Do you know why???? Here is the weird error:
    *** glibc detected *** bin/daemon_wallpapoz: free(): invalid next size (fast): 0x0929d7c8 ***
    ======= Backtrace: =========
    /lib/libc.so.6[0xcda424]
    /lib/libc.so.6(__libc_free+0x77)[0xcda95f]
    /usr/lib/libstdc++.so.6(_ZdlPv+0x21)[0x23d4669]
    /usr/lib/libstdc++.so.6(_ZdaPv+0x1d)[0x23d46b5]
    bin/daemon_wallpapoz[0x804afb1]
    /lib/libc.so.6(__libc_start_main+0xc6)[0xc8bde6]
    bin/daemon_wallpapoz(__gxx_personality_v0+0xa1)[0x804a3bd]
    ======= Memory map: ========
    00111000-0014b000 r-xp 00000000 03:02 1395090 /usr/lib/libatkmm-1.6.so.1.0.200014b000-0014f000 rwxp 00039000 03:02 1395090 /usr/lib/libatkmm-1.6.so.1.0.200014f000-00151000 r-xp 00000000 03:02 1392528 /usr/X11R6/lib/libXinerama.so.1.0
    00151000-00152000 rwxp 00001000 03:02 1392528 /usr/X11R6/lib/libXinerama.so.1.0
    00152000-00172000 r-xp 00000000 03:02 1380283 /usr/lib/libxml++-2.6.so.2.0.4
    00172000-00173000 rwxp 00020000 03:02 1380283 /usr/lib/libxml++-2.6.so.2.0.4
    00173000-003c1000 r-xp 00000000 03:02 1395094 /usr/lib/libgtkmm-2.4.so.1.0.20003c1000-00405000 rwxp 0024d000 03:02 1395094 /usr/lib/libgtkmm-2.4.so.1.0.2000405000-00417000 r-xp 00000000 03:02 1380275 /usr/lib/libz.so.1.2.2.2
    00417000-00418000 rwxp 00011000 03:02 1380275 /usr/lib/libz.so.1.2.2.2
    00418000-00494000 r-xp 00000000 03:02 1388701 /usr/lib/libgdk-x11-2.0.so.0.600.7
    00494000-0049b000 rwxp 0007c000 03:02 1388701 /usr/lib/libgdk-x11-2.0.so.0.600.7
    0049b000-004af000 r-xp 00000000 03:02 1394992 /usr/lib/libatk-1.0.so.0.901.0
    004af000-004b2000 rwxp 00014000 03:02 1394992 /usr/lib/libatk-1.0.so.0.901.0
    004b2000-004b5000 r-xp 00000000 03:02 1395151 /usr/lib/libgmodule-2.0.so.0.600.4
    004b5000-004b6000 rwxp 00002000 03:02 1395151 /usr/lib/libgmodule-2.0.so.0.600.4
    004b6000-004d9000 r-xp 00000000 03:02 1388690 /usr/lib/libpangoft2-1.0.so.0.800.1
    004d9000-004db000 rwxp 00022000 03:02 1388690 /usr/lib/libpangoft2-1.0.so.0.800.1
    005b3000-005c9000 r-xp 00000000 03:02 1392824 /usr/lib/libglade-2.0.so.0.0.7
    005c9000-005ca000 rwxp 00016000 03:02 1392824 /usr/lib/libglade-2.0.so.0.0.7
    005f5000-005f9000 r-xp 00000000 03:02 1392530 /usr/X11R6/lib/libXfixes.so.3.0005f9000-005fa000 rwxp 00003000 03:02 1392530 /usr/X11R6/lib/libXfixes.so.3.0005fe000-00605000 r-xp 00000000 03:02 1388921 /usr/X11R6/lib/libXrender.so.1.2.2
    00605000-00606000 rwxp 00007000 03:02 1388921 /usr/X11R6/lib/libXrender.so.1.2.2
    00608000-0060b000 r-xp 00000000 03:02 1390642 /usr/X11R6/lib/libXrandr.so.2.00060b000-0060c000 rwxp 00002000 03:02 1390642 /usr/X11R6/lib/libXrandr.so.2.00062e000-00637000 r-xp 00000000 03:02 1392531 /usr/X11R6/lib/libXcursor.so.1.0.2
    00637000-00638000 rwxp 00008000 03:02 1392531 /usr/X11R6/lib/libXcursor.so.1.0.2
    0063e000-00658000 r-xp 00000000 03:02 394428 /lib/ld-2.3.5.so
    00658000-00659000 r-xp 00019000 03:02 394428 /lib/ld-2.3.5.so
    00659000-0065a000 rwxp 0001a000 03:02 394428 /lib/ld-2.3.5.so
    006fb000-006fc000 r-xp 006fb000 00:00 0
    00788000-007aa000 r-xp 00000000 03:02 394430 /lib/libm-2.3.5.so
    007aa000-007ab000 r-xp 00021000 03:02 394430 /lib/libm-2.3.5.so
    007ab000-007ac000 rwxp 00022000 03:02 394430 /lib/libm-2.3.5.so
    007ae000-007b0000 r-xp 00000000 03:02 394431 /lib/libdl-2.3.5.so
    007b0000-007b1000 r-xp 00001000 03:02 394431 /lib/libdl-2.3.5.so
    007b1000-007b2000 rwxp 00002000 03:02 394431 /lib/libdl-2.3.5.so
    007c9000-00899000 r-xp 00000000 03:02 1382684 /usr/X11R6/lib/libX11.so.6.2
    00899000-0089d000 rwxp 000cf000 03:02 1382684 /usr/X11R6/lib/libX11.so.6.2
    0089f000-008ad000 r-xp 00000000 03:02 1388058 /usr/X11R6/lib/libXext.so.6.4
    008ad000-008ae000 rwxp 0000e000 03:02 1388058 /usr/X11R6/lib/libXext.so.6.4
    008b0000-008be000 r-xp 00000000 03:02 394432 /lib/libpthread-2.3.5.so
    008be000-008bf000 r-xp 0000d000 03:02 394432 /lib/libpthread-2.3.5.so
    008bf000-008c0000 rwxp 0000e000 03:02 394432 /lib/libpthread-2.3.5.so
    008c0000-008c2000 rwxp 008c0000 00:00 0
    008c4000-008e1000 r-xp 00000000 03:02 1394707 /usr/lib/libexpat.so.0.5.0
    008e1000-008e3000 rwxp 0001c000 03:02 1394707 /usr/lib/libexpat.so.0.5.0
    008e5000-00946000 r-xp 00000000 03:02 1387922 /usr/lib/libfreetype.so.6.3.7
    00946000-0094d000 rwxp 00061000 03:02 1387922 /usr/lib/libfreetype.so.6.3.7
    0094f000-00975000 r-xp 00000000 03:02 1388684 /usr/lib/libfontconfig.so.1.0.400975000-00978000 rwxp 00026000 03:02 1388684 /usr/lib/libfontconfig.so.1.0.400978000-00979000 rwxp 00978000 00:00 0
    0097b000-0098d000 r-xp 00000000 03:02 1388689 /usr/X11R6/lib/libXft.so.2.1.2
    0098d000-0098e000 rwxp 00012000 03:02 1388689 /usr/X11R6/lib/libXft.so.2.1.2
    00990000-0099a000 r-xp 00000000 03:02 1392533 /usr/lib/libpangox-1.0.so.0.800.1
    0099a000-0099b000 rwxp 00009000 03:02 1392533 /usr/lib/libpangox-1.0.so.0.800.1
    0099d000-009a2000 r-xp 00000000 03:02 1388694 /usr/lib/libpangoxft-1.0.so.0.800.1
    009a2000-009a3000 rwxp 00005000 03:02 1388694 /usr/lib/libpangoxft-1.0.so.0.800.1
    00a55000-00a78000 r-xp 00000000 03:02 1395096 /usr/lib/libpangomm-1.4.so.1.0.20
    00a78000-00a7a000 rwxp 00022000 03:02 1395096 /usr/lib/libpangomm-1.4.so.1.0.20
    00aa7000-00af5000 r-xp 00000000 03:02 1395086 /usr/lib/libglibmm-2.4.so.1.0.13
    00af5000-00af8000 rwxp 0004e000 03:02 1395086 /usr/lib/libglibmm-2.4.so.1.0.13
    00b06000-00b0d000 r-xp 00000000 03:02 1395084 /usr/lib/libsigc-2.0.so.0.0.0
    00b0d000-00b0e000 rwxp 00006000 03:02 1395084 /usr/lib/libsigc-2.0.so.0.0.0
    00b94000-00bcc000 r-xp 00000000 03:02 1395075 /usr/lib/libgobject-2.0.so.0.600.4
    00bcc000-00bd0000 rwxp 00037000 03:02 1395075 /usr/lib/libgobject-2.0.so.0.600.4
    00be2000-00beb000 r-xp 00000000 03:02 1395098 /usr/lib/libglademm-2.4.so.1.0.3
    00beb000-00bec000 rwxp 00009000 03:02 1395098 /usr/lib/libglademm-2.4.so.1.0.3
    00c12000-00c19000 r-xp 00000000 03:02 1392527 /usr/X11R6/lib/libXi.so.6.0
    00c19000-00c1a000 rwxp 00006000 03:02 1392527 /usr/X11R6/lib/libXi.so.6.0
    00c29000-00c59000 r-xp 00000000 03:02 1395154 /usr/lib/libpango-1.0.so.0.800.1
    00c59000-00c5f000 rwxp 00030000 03:02 1395154 /usr/lib/libpango-1.0.so.0.800.1
    00c61000-00c75000 r-xp 00000000 03:02 1395158 /usr/lib/libgdk_pixbuf-2.0.so.0.600.7
    00c75000-00c77000 rwxp 00013000 03:02 1395158 /usr/lib/libgdk_pixbuf-2.0.so.0.600.7
    00c77000-00d9b000 r-xp 00000000 03:02 394429 /lib/libc-2.3.5.so
    00d9b000-00d9d000 r-xp 00124000 03:02 394429 /lib/libc-2.3.5.so
    00d9d000-00d9f000 rwxp 00126000 03:02 394429 /lib/libc-2.3.5.so
    00d9f000-00da1000 rwxp 00d9f000 00:00 0
    00deb000-00df4000 r-xp 00000000 03:02 393347 /lib/libgcc_s-4.0.0-20050520.so.1
    00df4000-00df5000 rwxp 00009000 03:02 393347 /lib/libgcc_s-4.0.0-20050520.so.1
    00e3b000-00e7a000 r-xp 00000000 03:02 1395092 /usr/lib/libgdkmm-2.4.so.1.0.2000e7a000-00e7d000 rwxp 0003e000 03:02 1395092 /usr/lib/libgdkmm-2.4.so.1.0.2002320000-023ff000 r-xp 00000000 03:02 1385180 /usr/lib/libstdc++.so.6.0.4
    023ff000-02404000 rwxp 000df000 03:02 1385180 /usr/lib/libstdc++.so.6.0.4
    02404000-02409000 rwxp 02404000 00:00 0
    04528000-047f4000 r-xp 00000000 03:02 1388703 /usr/lib/libgtk-x11-2.0.so.0.600.7
    047f4000-0481b000 rwxp 002cc000 03:02 1388703 /usr/lib/libgtk-x11-2.0.so.0.600.7
    0481b000-0481e000 rwxp 0481b000 00:00 0
    0618c000-0629f000 r-xp 00000000 03:02 1392575 /usr/lib/libxml2.so.2.6.20
    0629f000-062a7000 rwxp 00113000 03:02 1392575 /usr/lib/libxml2.so.2.6.20
    062a7000-062a8000 rwxp 062a7000 00:00 0
    06bda000-06c5e000 r-xp 00000000 03:02 1387570 /usr/lib/libglib-2.0.so.0.600.406c5e000-06c63000 rwxp 00084000 03:02 1387570 /usr/lib/libglib-2.0.so.0.600.408048000-0804f000 r-xp 00000000 03:06 899 /mnt/data/work/wallpapoz/bin/daemon_wallpapoz
    0804f000-08050000 rw-p 00006000 03:06 899 /mnt/data/work/wallpapoz/bin/daemon_wallpapoz
    0924e000-092fb000 rw-p 0924e000 00:00 0 [heap]
    b2d00000-b2d21000 rw-p b2d00000 00:00 0
    b2d21000-b2e00000 ---p b2d21000 00:00 0
    b2ed4000-b2ed5000 rw-p b2ed4000 00:00 0
    b2ed5000-b2ed6000 ---p b2ed5000 00:00 0
    b2ed6000-b38d6000 rw-p b2ed6000 00:00 0
    b38d6000-b38d7000 ---p b38d6000 00:00 0
    b38d7000-b42d7000 rw-p b38d7000 00:00 0
    b42d7000-b42d8000 ---p b42d7000 00:00 0
    b42d8000-b4cd8000 rw-p b42d8000 00:00 0
    b4cd8000-b4cd9000 ---p b4cd8000 00:00 0
    b4cd9000-b56d9000 rw-p b4cd9000 00:00 0
    b56d9000-b56da000 ---p b56d9000 00:00 0
    b56da000-b60da000 rw-p b56da000 00:00 0
    b60da000-b60db000 ---p b60da000 00:00 0
    b60db000-b6adb000 rw-p b60db000 00:00 0
    b6adb000-b6adc000 ---p b6adb000 00:00 0
    b6adc000-b74dc000 rw-p b6adc000 00:00 0
    b74dc000-b74dd000 ---p b74dc000 00:00 0
    b74dd000-b7ee7000 rw-p b74dd000 00:00 0
    b7f02000-b7f03000 rw-p b7f02000 00:00 0
    bfded000-bfe03000 rw-p bfded000 00:00 0 [stack]
    Aborted
    A man asked, "Who are you?"
    Buddha answered, "I am awaked."

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,821
    > arg_list[5] = new char[ wallpaper[ chars_read ].at( number[ chars_read ] ).length() ];
    > strcpy(arg_list[5],wallpaper[chars_read].at(number[chars_read]).c_str());
    Well I'd say you forgot to count the \0 you'll need when you make a copy of the string.

    Say
    Code:
    	    arg_list[5] = new char[ wallpaper[ chars_read ].at( number[ chars_read ] ).length() + 1 ];
    	    strcpy(arg_list[5],wallpaper[chars_read].at(number[chars_read]).c_str());
    > my program will ( always ) crash if it encounter with certain wallpaper
    Well for efficiently purposes, most memory allocations pad the end with a few unused bytes to round up the size you request to some nice number (say a multiple of 4). The result is you can silently fail by overwriting these padding bytes with a \0 and nothing will happen.
    If on the other hand, you have a length which requires no padding bytes, then the extra \0 you write really does end up somwhere it shouldn't, and the predictable result is BOOM!

    gcc prog.c -lefence
    Should spot you trying to access even padding bytes, which would spot the problem much sooner.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User gandalf_bar's Avatar
    Join Date
    Oct 2003
    Posts
    92
    Thank you, Salem! That explain why my application got weird error beside this. When encounter certain wallpaper, it output: Error: Text contain invalid UTF-8 or something like that but does not make crash. Now I know why I got that two weird errors.
    A man asked, "Who are you?"
    Buddha answered, "I am awaked."

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. how do you resolve this error?
    By -EquinoX- in forum C Programming
    Replies: 32
    Last Post: 11-05-2008, 04:35 PM
  2. Errors including <windows.h>
    By jw232 in forum Windows Programming
    Replies: 4
    Last Post: 07-29-2008, 02:29 PM
  3. Quantum Random Bit Generator
    By shawnt in forum C++ Programming
    Replies: 62
    Last Post: 06-18-2008, 11:17 AM
  4. Connecting to a mysql server and querying problem
    By Diod in forum C++ Programming
    Replies: 8
    Last Post: 02-13-2006, 10:33 AM
  5. very weird .h problem
    By royuco77 in forum C++ Programming
    Replies: 1
    Last Post: 09-11-2005, 08:55 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21