新/删除操作不匹配错误有多严重? [英] How serious is the new/delete operator mismatch error?

查看:70
本文介绍了新/删除操作不匹配错误有多严重?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我们的代码库中发现了经典的新/删除不匹配错误,如下所示:

I have discovered the classic new/delete mismatch error in our codebase as follows:

char *foo = new char[10];

// do something

delete foo; // instead of delete[] foo;

这有多严重?它是否会导致内存泄漏或错误?后果是什么。我们有一些内存问题,但这似乎不足以解释我们的所有症状(堆腐败等)

Just how serious is this? Does it cause a memory leak or error? What are the consequences. We have some memory issues, but this doesn't seem serious enough to explain all our symptoms (heap corruption etc)

编辑:额外的问题为了清楚

它只是释放数组的第一个成员?或

是否使系统失去对阵列的跟踪?或

损坏的内存是某种方式?

extra questions for clarity
Does it just free the first member of the array? or
Does it make the system lose track of the array? or
Corrupt memory is some way?

推荐答案

这是未定义的行为严重崩溃,它可以做别的事情)。

It's undefined behavior serious (it could work, it could crash, it could do something else).

这篇关于新/删除操作不匹配错误有多严重?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆