Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

The solution of bug in Linux

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

The solution of bug in Linux, in view of this problem, this article introduces the corresponding analysis and solution in detail, hoping to help more partners who want to solve this problem to find a more simple and feasible method.

Recently, a problem encountered during debugging is that in the absence of a GPS signal, the following error message appears after a few minutes of each run, causing the program to interrupt and exit:

Double free or corruption (out)

Aborted (core dumped) this question has been bothering me for about two hours. I would like to make a summary here. At first I checked the code to see if there was any double free, and found that it didn't. Later, I added to the code the judgment of the success of malloc and the statement that the pointer is assigned to NULL after free, which is still the same problem. Later, I opened the log, and suddenly found a phenomenon in the process, that is, every time the program hung up, the serial port read the data length of 450bytes. If you look carefully, you actually read two strings of data, that is, two GNRMC and other statements. Buff len:450 $GNRMC,V,N*4D$GNVTG,N*2E$GNGGA,0,00,99.99,*56$ GNGSA,A,1,99.99,99.99,99.99*2E$GNGSA,A,1,99.99,99.99,99.99*2E$GPGSV,1,1,00*79$ GLGSV,1,1,00*65$ GNGLL,V,N*7A$GNRMC,V 56$ GNGSA,A,1,99.99,99.99,99.99*2E$GNGSA,A,1,99.99,99.99,99.99*2E$GPGSV,1,1,00*79$ GLGSV,1,1,00*65$ GNGLL,V,N*7Adouble free or corruption (out)

Aborted (core dumped)

Normally, you read the following message, that is, there is only one GNRMC statement.

Buff len:225;$GNRMC,V,N*4D$GNVTG,N*2E$GNGGA,0,00,99.99,*56$ GNGSA,A,1,99.99,99.99,99.99*2E$GNGSA,A,1,99.99,99.99,99.99*2E$GPGSV,1,1,00*79$ GLGSV,1,1,00*65

$GNGLL,V,N*7A

With this clue, it is easy to find the problem. The problem lies in the extra number 100 when the following function malloc allocates space.

Int gps_analyse (char * buff,int buff_len,GNSS * gps_data)

{

……

Char * tmpbuf

Tmpbuf = (char *) malloc (strlen (ptr) + 100)

Memset (tmpbuf, 0, strlen (ptr) + 100)

Memcpy (tmpbuf, ptr, strlen (ptr))

While (strstr (tmpbuf, ","))

Strrpl (tmpbuf, ", @,")

……

This 100 is originally intended to be used to replace @ for that particular state above, there are a total of 114 consecutive, so there is not enough space allocation, which leads to problems. The solution is also simple, as long as you increase the 100. This question enlightens me as follows: 1) malloc must pay attention to the size when allocating space; 2) cover all possible situations during the test, not just consider the normal state. I have only measured the state when there is a GPS signal before.

3) the testing time should be long enough.

This is the answer to the question about the solution of bug in Linux. I hope the above content can be of some help to you. If you still have a lot of doubts to be solved, you can follow the industry information channel for more related knowledge.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report