invalid null pointerpointer dequeued from free list 内存错误怎么解决

全局变量与 *** glibc detected *** ./1: free(): invalid pointer错误_C语言_第七城市
全局变量与 *** glibc detected *** ./1: free(): invalid pointer错误
以前上课的时候,老师总是说全局变量不要随便用,当时也只是记得这个说法,至于为什么也没仔细研究。结果最近写代码的时候果断跪了。其实内存泄露跟全局变量的使用没有因果关系,只不过是我在写代码的时候犯2了。下面是我在做深度优先搜索的时候写的一段代码:void dfs(int c){ //error 2
if(c == c2) {
if(path == dist[c2])
count += 1;
if(max & hand)
if(path & dist[c2])
for(i=0;i&n;i++) {
if(arcs[c][i]!=INFINITY && !s[i])
path += arcs[c][i];
hand += teams[i];
path -= arcs[c][i];
hand -= teams[i];
} }}代码中的数组都是指针通过malloc动态申请的,这些指针都是全局变量。为了图方便,我把i,j这些变量也直接声明成全局变量了。结果问题来了。在DFS代码中忘记重新声明一个i变量用于迭代了,而i这个变量作为全局变量还在,导致编译的时候也不会找到这个错误。如果是C++倒是可能不会有这个问题,一般在for循环内部我都重新声明i变量。就算是i用的是全局变量,最有可能也是逻辑上得到的结果是错误的,为什么会出现内存泄露这种不相关的错误呢?arcs是n*n的数组,这里假设n=5。那么在for循环第一次i等于0,假设arcs[0][1]是有路径的,也就是说能够进入if内的逻辑。那么根据深度搜索那么下一次递归调用dfs的时候,参数就变成了1。再对1做深度搜索的时候,不管for内部的if是否成立,for迭代都是要做完的。这样迭代完了之后i的值一定是5(n=5),然后返回上一层,此时上一层i的值理应为1,但是由于i是全局变量,此时i的值是5。看dfs(i)下一句path -= arcs[c][i];按理说应该取的是arcs[c][1],但是结果却取成了arcs[c][5],又因为arcs在申请空间的时候取的是5×5,这样一来,直接就造成了数组越界,所以在最后free这个指针的时候才会导致内存泄露。因为实际上使用的空间与申请的空间已经不一致了。
最新教程周点击榜
微信扫一扫xcode报错记录(21)
偶然遇到的bug , 暂没有解决
() malloc: * error for object 0x: Invalid pointer dequeued from free list
* set a breakpoint in malloc_error_break to debug
l(d39000) malloc: * error for object 0x7f: Invalid signature for pointer dequeued from free list
* set a breakpoint in malloc_error_break to debug
参考知识库
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:17454次
积分:1023
积分:1023
排名:千里之外
原创:86篇
转载:10篇
(3)(6)(19)(2)(2)(3)(2)(3)(2)(8)(13)(14)(17)(2)Pages: 1/2
主题 : 内存问题。。求救
级别: 新手上路
UID: 511408
可可豆: 246 CB
威望: 159 点
在线时间: 178(时)
发自: Web Page
来源于&&分类
内存问题。。求救&&&
运行的时候偶尔会出现这个错误,malloc: *** error for object 0x: Invalid pointer dequeued from free但是我打开Zombie Objects来查找哪出的问题的时候,项目就不会崩了。。这是什么问题。。大神们。。求解
级别: 新手上路
UID: 511408
可可豆: 246 CB
威望: 159 点
在线时间: 178(时)
发自: Web Page
级别: 圣骑士
UID: 579655
可可豆: 1479 CB
威望: 1257 点
在线时间: 252(时)
发自: Web Page
你看崩在哪里啊,然后看看指针哪里有问题,不行百度看,内存问题应该是那哪里没有处理好
男孩子一直不谈恋爱就永远是男孩子,女孩子一直不谈恋爱就会变成大叔。
级别: 侠客
可可豆: 295 CB
威望: 290 点
在线时间: 502(时)
发自: Web Page
一看小伙子的问题,就知道小伙子肯定用上了多线程,我就遇到过这种情况,我的是崩在array,解决办法就是我不再使用array,使用int型的变量来存储array的数量,使用NSData来存array里的数据...你根据需求来规划自己的解决办法吧,我只是说下我的经验...
级别: 新手上路
UID: 511408
可可豆: 246 CB
威望: 159 点
在线时间: 178(时)
发自: Web Page
回 3楼(清墨墨) 的帖子
感谢你们解答。。我的项目里面是有用多线程,但是崩的地方并不是在运用多线程的地方。。我做了一个Excepotion Breakpoint 确实是断在了带有数组的地方。。这个数组里面装的是多个ViewController 用于tabBarControl.viewControllers的指向。。大神觉得是这里原因吗??要是的话,我这个数组要怎么改那??
级别: 侠客
UID: 546956
可可豆: 415 CB
威望: 379 点
在线时间: 152(时)
发自: Web Page
数组打印出来看看情况
级别: 侠客
UID: 371193
可可豆: 574 CB
威望: 464 点
在线时间: 260(时)
发自: Web Page
回 4楼(liruo2013) 的帖子
这个数组里面装的是多个ViewController 用于tabBarControl.viewControllers的指向?干啥用的,tabBarControl几个界面的切换用?
级别: 骑士
UID: 593036
可可豆: 548 CB
威望: 442 点
在线时间: 159(时)
发自: Web Page
我这个东西找了1个多月了,还没找到呢。什么办法都试过了,感觉并不是数组的问题。我准备实时跟进你这个帖子~
级别: 骑士
UID: 593036
可可豆: 548 CB
威望: 442 点
在线时间: 159(时)
发自: Web Page
绑顶~123456上山打老虎!!!
级别: 新手上路
UID: 511408
可可豆: 246 CB
威望: 159 点
在线时间: 178(时)
发自: Web Page
回 5楼(w) 的帖子
这个已经看过了数组里面的内容是没有问题的
Pages: 1/2
关注本帖(如果有新回复会站内信通知您)
苹果公司现任CEO是谁?2字 正确答案:库克
发帖、回帖都会得到可观的积分奖励。
按"Ctrl+Enter"直接提交
关注CocoaChina
关注微信 每日推荐
扫一扫 浏览移动版Javascript Disabled Detected
You currently have javascript disabled. Several functions may not work. Please re-enable javascript to access full functionality.
App Update Denied - Crashes on iPad Mini Wifi
Started by , Mar 20
Please log in to reply
15 replies to this topic
As title says, got an errer report file (.sdx) that looks like the action is happening here:
23:57:06.232 CrappyBirdV1_1_15_02_20[206]: &Error& CrappyBirdV1_1_15_02_20(206,0x19aa46310) malloc: *** error for object 0x1700afc00: Invalid pointer dequeued from free list
*** set a breakpoint in malloc_error_break to debug
Thread 0 name:  Dispatch queue: com.apple.main-thread
Thread 0 Crashed:
Please advise
     
 |  |  |  |  |  |  |
RIP GMC. ;_;
pls send halp
     
 |  |  |  |  |  |  |
RIP GMC. ;_;
@zbox, I have those issues come up as well, and it seems a lot of it is within the GM runner/virtual machine. I was getting crashes in using the New Audio Engine and using iOS extensions. I have also read others have made a minor change unrelated to their crash, and the app will work/pass.
Have you run your app under the simulator? I can duplicate my crash pretty consistently when using the iPad Air simulator under XCode.
Also, if you can post the full *.ips crash report, that will help to see where the crash is occuring...
But I think all you can do is log a bug report and attach the *.ips file with your app. It's probably out of your hands...
Fluency Games, LLC /    /    /  
        
I have the same problem, binary rejected because of a game crash and when i check the ips logfile i find the same error.
"malloc: *** error for object 0x1702bfb00: Invalid pointer dequeued from free list."
The game runs fine on all test devices and this only appears in one game with a similar name than yours @zbox.. hmm.
They sent me a screenshot when the crash happens and there is the background color in fullscreen when the game crashes.
I cannot reproduce the error in xcode with the simulators, because of a application linker error. Did you get arround this somehow?
Sky Mercenaries - Now on  - 
more games @  -  -  - 
as mesterman says this sounds this is probably out of our hands, hence why I posted here originally. Sent a help ticket... fun fun fun
     
 |  |  |  |  |  |  |
RIP GMC. ;_;
@irjoedirt -- There is a setting in the GGS for iOS-- you can change the development target from Device to S in the simulator you can change the device.
Fluency Games, LLC /    /    /  
        
Today, I got this error for iPad Air, too. Do we at least know what causes this problem to occur in the first place? Is it the iOS ad extension as usual?
about ready to nail my testicle sack to the floor
     
 |  |  |  |  |  |  |
RIP GMC. ;_;
...I was using other iOS extensions and having the crash. I was told by YYG Games QA (and Russell) that the author of the extension had to include compiled libraries for 32- and 64-bit, and also for the simulators (Which there is no documentation or annuoncement from YYG that this was a major change). However, this is being addressed and hopefully will be resolved ... sooner than later, hopefully.
Fluency Games, LLC /    /    /  
        
  That was this problem.  
What's irking me is no new STEAM beta updates since the fix was put in 24 days ago.    I need this fixed so I can ship.
I click you link and see the reply,but I don't understand what the developer means.
Could you please explain it for me in simple English?
The HeyZap Mediation Ads extension.  Easy to work with, and you can choose one or more ads through it, including Adcolony, Admob, Charboost, Unity Ads, Vungle, and so on.
When you add this ext into your game, you can turn on/off the ads you want on the dashboard of Heyzap.
Is this fix live in any version of game maker?
Check out Blocky Kong on Android and iOS:
Nope - not as far as I can find, and it was fixed on the 1st of May according to the logs.   I know the guys at YoYo are busy but why in the name of all good engineers have they not released a patch fixing a sev 0 pri 0 bug preventing the ship of apps on iOS that require native iOS extensions.  
 ----
The short of it is that int pointers in 32b are smaller than 64b and in a 64b run-time environment it's causing bad memory reads (esp if you have more than one plugin) because it's looking at the wrong memory address.   
OK,I see.Is that mean the Yoyo engineers are working for these issues,or they have finished it?
Nope - not as far as I can find, and it was fixed on the 1st of May according to the logs.   I know the guys at YoYo are busy but why in the name of all good engineers have they not released a patch fixing a sev 0 pri 0 bug preventing the ship of apps on iOS that require native iOS extensions.  
  ----
The short of it is that int pointers in 32b are smaller than 64b and in a 64b run-time environment it's causing bad memory reads (esp if you have more than one plugin) because it's looking at the wrong memory address.   
The HeyZap Mediation Ads extension.  Easy to work with, and you can choose one or more ads through it, including Adcolony, Admob, Charboost, Unity Ads, Vungle, and so on.
When you add this ext into your game, you can turn on/off the ads you want on the dashboard of Heyzap.
its out in the latest early access now
not going to lie pretty ridiculous how long it took not to mention that it STILL is not available in a stable or even beta gm build
     
 |  |  |  |  |  |  |
RIP GMC. ;_;
Sadly my client I'm waiting to ship one won't accept EA, it has to at least make it to the Beta channel.   I just wish Yoyo would get on the ball, this client is one of those major clients with more money and clout than you can shake a stick at, and they are getting really pissed with GMS and wishing they had paid the little bit extra to have had the work done in Unity.  
Reply to quoted posts&&&&& &&&
Need an account?
Forum Password
Remember me
This is not recommended for shared computers
Sign in anonymously
Don't add me to the active users list}

我要回帖

更多关于 invalid null pointer 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信