当前位置 博文首页 > lyndon:常见的内存报错原因

    lyndon:常见的内存报错原因

    作者:[db:作者] 时间:2021-09-15 10:18

    invalid next size (fast)

    出错原因:内存地址越界

    #include <stdio.h>
    #include <stdlib.h>
    
    int main(int argc, char *argv[])
    {
        char *p = malloc(4);
        char *x = malloc(4);
    
        for (int i = 0; i < 30; i++)
        {
            p[i] = 'a';
        }
    
        printf("%s\n", p);
    
        free(p);
    
        return 0;
    }
    
    $ gcc main.c 
    $ ./a.out 
    aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
    *** Error in `./a.out': free(): invalid next size (fast): 0x0000000000d25010 ***
    ======= Backtrace: =========
    /lib/x86_64-linux-gnu/libc.so.6(+0x777e5)[0x7fce801a17e5]
    /lib/x86_64-linux-gnu/libc.so.6(+0x8037a)[0x7fce801aa37a]
    /lib/x86_64-linux-gnu/libc.so.6(cfree+0x4c)[0x7fce801ae53c]
    ./a.out[0x40061c]
    /lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xf0)[0x7fce8014a830]
    ./a.out[0x4004e9]
    ======= Memory map: ========
    00400000-00401000 r-xp 00000000 08:01 6455206                            /home/liyongjun/project/my/c/0126/a.out
    00600000-00601000 r--p 00000000 08:01 6455206                            /home/liyongjun/project/my/c/0126/a.out
    00601000-00602000 rw-p 00001000 08:01 6455206                            /home/liyongjun/project/my/c/0126/a.out
    00d25000-00d46000 rw-p 00000000 00:00 0                                  [heap]
    7fce7bdea000-7fce7be00000 r-xp 00000000 08:01 3806157                    /lib/x86_64-linux-gnu/libgcc_s.so.1
    7fce7be00000-7fce7bfff000 ---p 00016000 08:01 3806157                    /lib/x86_64-linux-gnu/libgcc_s.so.1
    7fce7bfff000-7fce7c000000 rw-p 00015000 08:01 3806157                    /lib/x86_64-linux-gnu/libgcc_s.so.1
    7fce7c000000-7fce7c021000 rw-p 00000000 00:00 0 
    7fce7c021000-7fce80000000 ---p 00000000 00:00 0 
    7fce8012a000-7fce802ea000 r-xp 00000000 08:01 3812110                    /lib/x86_64-linux-gnu/libc-2.23.so
    7fce802ea000-7fce804ea000 ---p 001c0000 08:01 3812110                    /lib/x86_64-linux-gnu/libc-2.23.so
    7fce804ea000-7fce804ee000 r--p 001c0000 08:01 3812110                    /lib/x86_64-linux-gnu/libc-2.23.so
    7fce804ee000-7fce804f0000 rw-p 001c4000 08:01 3812110                    /lib/x86_64-linux-gnu/libc-2.23.so
    7fce804f0000-7fce804f4000 rw-p 00000000 00:00 0 
    7fce804f4000-7fce8051a000 r-xp 00000000 08:01 3812091                    /lib/x86_64-linux-gnu/ld-2.23.so
    7fce806ee000-7fce806f1000 rw-p 00000000 00:00 0 
    7fce80718000-7fce80719000 rw-p 00000000 00:00 0 
    7fce80719000-7fce8071a000 r--p 00025000 08:01 3812091                    /lib/x86_64-linux-gnu/ld-2.23.so
    7fce8071a000-7fce8071b000 rw-p 00026000 08:01 3812091                    /lib/x86_64-linux-gnu/ld-2.23.so
    7fce8071b000-7fce8071c000 rw-p 00000000 00:00 0 
    7ffe8b88e000-7ffe8b8b0000 rw-p 00000000 00:00 0                          [stack]
    7ffe8b8d4000-7ffe8b8d7000 r--p 00000000 00:00 0                          [vvar]
    7ffe8b8d7000-7ffe8b8d9000 r-xp 00000000 00:00 0                          [vdso]
    ffffffffff600000-ffffffffff601000 r-xp 00000000 00:00 0                  [vsyscall]
    已放弃 (核心已转储)
    

    double free or corruption (fasttop)

    出错原因:重复释放

    #include <stdio.h>
    #include <stdlib.h>
    
    int main(int argc, char *argv[])
    {
        char *p = malloc(4);
        // char *x = malloc(4);
    
        for (int i = 0; i < 4; i++)
        {
            p[i] = 'a';
        }
    
        printf("%s\n", p);
    
        free(p);
        free(p);
    
        return 0;
    }
    
    $ gcc main.c 
    $ ./a.out 
    aaaa
    *** Error in `./a.out': double free or corruption (fasttop): 0x0000000001439010 ***
    ======= Backtrace: =========
    /lib/x86_64-linux-gnu/libc.so.6(+0x777e5)[0x7ff04d8187e5]
    /lib/x86_64-linux-gnu/libc.so.6(+0x8037a)[0x7ff04d82137a]
    /lib/x86_64-linux-gnu/libc.so.6(cfree+0x4c)[0x7ff04d82553c]
    ./a.out[0x40061a]
    /lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xf0)[0x7ff04d7c1830]
    ./a.out[0x4004e9]
    ======= Memory map: ========
    00400000-00401000 r-xp 00000000 08:01 6455206                            /home/liyongjun/project/my/c/0126/a.out
    00600000-00601000 r--p 00000000 08:01 6455206                            /home/liyongjun/project/my/c/0126/a.out
    00601000-00602000 rw-p 00001000 08:01 6455206                            /home/liyongjun/project/my/c/0126/a.out
    01439000-0145a000 rw-p 00000000 00:00 0                                  [heap]
    7ff048000000-7ff048021000 rw-p 00000000 00:00 0 
    7ff048021000-7ff04c000000 ---p 00000000 00:00 0 
    7ff04d58b000-7ff04d5a1000 r-xp 00000000 08:01 3806157                    /lib/x86_64-linux-gnu/libgcc_s.so.1
    7ff04d5a1000-7ff04d7a0000 ---p 00016000 08:01 3806157                    /lib/x86_64-linux-gnu/libgcc_s.so.1
    7ff04d7a0000-7ff04d7a1000 rw-p 00015000 08:01 3806157                    /lib/x86_64-linux-gnu/libgcc_s.so.1
    7ff04d7a1000-7ff04d961000 r-xp 00000000 08:01 3812110                    /lib/x86_64-linux-gnu/libc-2.23.so
    7ff04d961000-7ff04db61000 ---p 001c0000 08:01 3812110                    /lib/x86_64-linux-gnu/libc-2.23.so
    7ff04db61000-7ff04db65000 r--p 001c0000 08:01 3812110                    /lib/x86_64-linux-gnu/libc-2.23.so
    7ff04db65000-7ff04db67000 rw-p 001c4000 08:01 3812110                    /lib/x86_64-linux-gnu/libc-2.23.so
    7ff04db67000-7ff04db6b000 rw-p 00000000 00:00 0 
    7ff04db6b000-7ff04db91000 r-xp 00000000 08:01 3812091                    /lib/x86_64-linux-gnu/ld-2.23.so
    7ff04dd65000-7ff04dd68000 rw-p 00000000 00:00 0 
    7ff04dd8f000-7ff04dd90000 rw-p 00000000 00:00 0 
    7ff04dd90000-7ff04dd91000 r--p 00025000 08:01 3812091                    /lib/x86_64-linux-gnu/ld-2.23.so
    7ff04dd91000-7ff04dd92000 rw-p 00026000 08:01 3812091                    /lib/x86_64-linux-gnu/ld-2.23.so
    7ff04dd92000-7ff04dd93000 rw-p 00000000 00:00 0 
    7fffc9a71000-7fffc9a93000 rw-p 00000000 00:00 0                          [stack]
    7fffc9bab000-7fffc9bae000 r--p 00000000 00:00 0                          [vvar]
    7fffc9bae000-7fffc9bb0000 r-xp 00000000 00:00 0                          [vdso]
    ffffffffff600000-ffffffffff601000 r-xp 00000000 00:00 0                  [vsyscall]
    已放弃 (核心已转储)
    

    free(): invalid pointer

    出错原因:释放的地址不是 malloc 申请的

    编译时有警告提醒

    #include <stdio.h>
    #include <stdlib.h>
    
    int main(int argc, char *argv[])
    {
        char p[1];
    
        free(p);
    
        return 0;
    }
    
    $ gcc main.c 
    main.c: In function ‘main’:
    main.c:8:5: warning: attempt to free a non-heap object ‘p’ [-Wfree-nonheap-object]
         free(p);
         ^
    $ ./a.out 
    *** Error in `./a.out': free(): invalid pointer: 0x00007ffd28125e67 ***
    ======= Backtrace: =========
    /lib/x86_64-linux-gnu/libc.so.6(+0x777e5)[0x7fd41e4e87e5]
    /lib/x86_64-linux-gnu/libc.so.6(+0x8037a)[0x7fd41e4f137a]
    /lib/x86_64-linux-gnu/libc.so.6(cfree+0x4c)[0x7fd41e4f553c]
    ./a.out[0x4005c0]
    /lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xf0)[0x7fd41e491830]
    ./a.out[0x4004c9]
    ======= Memory map: ========
    00400000-00401000 r-xp 00000000 08:01 6455206                            /home/liyongjun/project/my/c/0126/a.out
    00600000-00601000 r--p 00000000 08:01 6455206                            /home/liyongjun/project/my/c/0126/a.out
    00601000-00602000 rw-p 00001000 08:01 6455206                            /home/liyongjun/project/my/c/0126/a.out
    7fd418000000-7fd418021000 rw-p 00000000 00:00 0 
    7fd418021000-7fd41c000000 ---p 00000000 00:00 0 
    7fd41e25b000-7fd41e271000 r-xp 00000000 08:01 3806157                    /lib/x86_64-linux-gnu/libgcc_s.so.1
    7fd41e271000-7fd41e470000 ---p 00016000 08:01 3806157                    /lib/x86_64-linux-gnu/libgcc_s.so.1
    7fd41e470000-7fd41e471000 rw-p 00015000 08:01 3806157                    /lib/x86_64-linux-gnu/libgcc_s.so.1
    7fd41e471000-7fd41e631000 r-xp 00000000 08:01 3812110                    /lib/x86_64-linux-gnu/libc-2.23.so
    7fd41e631000-7fd41e831000 ---p 001c0000 08:01 3812110                    /lib/x86_64-linux-gnu/libc-2.23.so
    7fd41e831000-7fd41e835000 r--p 001c0000 08:01 3812110                    /lib/x86_64-linux-gnu/libc-2.23.so
    7fd41e835000-7fd41e837000 rw-p 001c4000 08:01 3812110                    /lib/x86_64-linux-gnu/libc-2.23.so
    7fd41e837000-7fd41e83b000 rw-p 00000000 00:00 0 
    7fd41e83b000-7fd41e861000 r-xp 00000000 08:01 3812091                    /lib/x86_64-linux-gnu/ld-2.23.so
    7fd41ea35000-7fd41ea38000 rw-p 00000000 00:00 0 
    7fd41ea5f000-7fd41ea60000 rw-p 00000000 00:00 0 
    7fd41ea60000-7fd41ea61000 r--p 00025000 08:01 3812091                    /lib/x86_64-linux-gnu/ld-2.23.so
    7fd41ea61000-7fd41ea62000 rw-p 00026000 08:01 3812091                    /lib/x86_64-linux-gnu/ld-2.23.so
    7fd41ea62000-7fd41ea63000 rw-p 00000000 00:00 0 
    7ffd28106000-7ffd28128000 rw-p 00000000 00:00 0                          [stack]
    7ffd28197000-7ffd2819a000 r--p 00000000 00:00 0                          [vvar]
    7ffd2819a000-7ffd2819c000 r-xp 00000000 00:00 0                          [vdso]
    ffffffffff600000-ffffffffff601000 r-xp 00000000 00:00 0                  [vsyscall]
    已放弃 (核心已转储)
    

    corrupted size vs. prev_size

    待续

    cs
    下一篇:没有了
什么是ALPHA?_cumtb2002的博客:什么是alpha测试 xiaojing0511的博客:Alpha测试和Beta测试的区别 SecondJanuary:Alpha测试(α测试) / Beta测试(β测试) 英雄哪里出来:??13万字《C语言动漫对话教程(入门篇)》??(建议收 xpj8888的博客:第三周 超参数调试、Batch正则化和程序框架:3. xpj8888的博客:wordpress插件管理(五)WP 数学公式插件 LaTeX xpj8888的博客:PyCharm2019.3.4 License key is in legacy form 大番薯:编程术语英汉对照 HashFlag的博客:Python基础 风信子的猫Redamancy的快乐星球:PRML - Chapter 02 Probability g5703129的博客:java学习笔记总结,持续更新中 晴天的专栏:怎样规划你毕业以后的人生 骑毛驴的猴的博客:【2020-11-04】JS逆向之某宝模拟登入 骑毛驴的猴的博客:【2020-11-05】Flask+uWGSI+Nginx的部署 骑毛驴的猴的博客:【2020-11-11】JS逆向之蘑菇街商品数据接口解 骑毛驴的猴的博客:【2020-11-16】Python反爬虫之字体反爬 骑毛驴的猴的博客:【2020-11-22】JS逆向之某团美食商铺数据获取 骑毛驴的猴的博客:【2020-11-26】不扣JS系列之某医保服务平台数 骑毛驴的猴的博客:【2020-11-30】猿人学任务一之js混淆 - 源码 骑毛驴的猴的博客:【2020-12-11】JS逆向之某某排污监测信息发布 骑毛驴的猴的博客:【2020-12-16】JS逆向之某变IP 骑毛驴的猴的博客:【2020-12-23】JS逆向之某在线监测分析平台 骑毛驴的猴的博客:【2021-01-05】JS逆向之B站模拟登入(含极验 骑毛驴的猴的博客:【2021-01-11】JS逆向之美团模拟登入 骑毛驴的猴的博客:【2021-01-14】JS逆向之招标投标公告服务平台 骑毛驴的猴的博客:【2021-01-22】JS逆向之七麦数据analysis获取 骑毛驴的猴的博客:【2021-01-27】JS逆向之某片滑块参数分析 骑毛驴的猴的博客:【2021-01-29】JS逆向之数美滑块参数分析 骑毛驴的猴的博客:【2021-02-05】JS逆向之某某银行理财产品 骑毛驴的猴的博客:【2021-02-19】JS逆向之365玩游戏平台(worke 骑毛驴的猴的博客:【2021-03-16】JS逆向之有赞滑块分析 骑毛驴的猴的博客:【2021-03-17】JS逆向之某实时票房榜数据解密 骑毛驴的猴的博客:【2021-03-23】JS逆向之站D爷免费代理 骑毛驴的猴的博客:小红书接口参数X-sign 骑毛驴的猴的博客:【2021-04-02】JS逆向之某查查pe端cookie分析 骑毛驴的猴的博客:【2021-07-15】JS逆向之网易云音乐登入--最新 骑毛驴的猴的博客:【2021-07-15】小红书web端数美验证码 骑毛驴的猴的博客:【2021-04-14】xhs小程序端滑块验证码 骑毛驴的猴的博客:【2021-04-23】JS逆向之某船舶物资采购平台动 骑毛驴的猴的博客:【2021-04-25】APP逆向之某智网加密数据 骑毛驴的猴的博客:【2021-05-06】JS逆向之微店登入ua 骑毛驴的猴的博客:【2021-05-07】JS逆向之①号店登入(含滑块) 骑毛驴的猴的博客:【2021-05-12】JS逆向之dy创作者平台登入滑块 骑毛驴的猴的博客:【2021-05-25】JS逆向之某酷视频搜索接口(面 骑毛驴的猴的博客:【2021-06-03】JS逆向之wm世界主页滑块 骑毛驴的猴的博客:【2021-06-07】JS逆向之同花顺cookie(最新v值 signature(最新)_骑毛驴的猴的博客:【2021-08-31】抖音web参数 骑毛驴的猴的博客:【2021-07-01】JS逆向之房xx滑块 骑毛驴的猴的博客:【2021-07-16】堆糖小程序 zes_96_骑毛驴的猴的博客:【2021-07-23】JS逆向之某乎x ASP.NET Core MVC 修改视图的默认路径及其实现原理解析 docker compose 一键部署分布式配置中心Apollo的过程详解 使用SQL SERVER存储过程实现历史数据迁移方式 Django框架之django admin的命令行详解 解决python将xml格式文件转换成txt文件的问题(xml.etree方法) 网站加速哪家强?四大免费CDN服务评测大PK php session无法传值怎么办 macbook pro怎么安装php7 高质量笔记来了!关于PHP7性能优化 php轻松实现可爱的随机头像 微信公众账号怎么注册申请?微信公众账号注册流程 微信公众平台服务号、订阅号和企业号之间有什么区别? android Chronometer控件使用大全 关于python变量的引用以及在底层存储原理 SpringBoot 在项目启动之后执行自定义方法的两种方式小结 uniapp实现滑动评分效果 vue中LocalStorage与SessionStorage的区别与用法 SEO案例分析 alimama做SEO引流量的方法 如何解决php图片名中文乱码问题 php命令行输出乱码怎么办