CN109933525A - A kind of general method for detecting memory leakage - Google Patents

A kind of general method for detecting memory leakage Download PDF

Info

Publication number
CN109933525A
CN109933525A CN201910131891.7A CN201910131891A CN109933525A CN 109933525 A CN109933525 A CN 109933525A CN 201910131891 A CN201910131891 A CN 201910131891A CN 109933525 A CN109933525 A CN 109933525A
Authority
CN
China
Prior art keywords
pointer
memory
application
address
general method
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN201910131891.7A
Other languages
Chinese (zh)
Inventor
刘小平
张华�
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
SHENZHEN JIXIANG TENDA TECHNOLOGY Co Ltd
Original Assignee
SHENZHEN JIXIANG TENDA TECHNOLOGY Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by SHENZHEN JIXIANG TENDA TECHNOLOGY Co Ltd filed Critical SHENZHEN JIXIANG TENDA TECHNOLOGY Co Ltd
Priority to CN201910131891.7A priority Critical patent/CN109933525A/en
Publication of CN109933525A publication Critical patent/CN109933525A/en
Pending legal-status Critical Current

Links

Abstract

The present invention provides a kind of general method for detecting memory leakage, comprising the following steps: step (1): by the embedded assembly code for obtaining RA pointer of malloc/free, recording RA pointer value;Step (2): after malloc memory application success, address is recorded in array;When free discharges successfully, by the record purge in array;Step (3): the data of buffer area are classified using RA, the application of each identical RA pointer is counted, the present invention is by way of recording RA pointer, the title for remembeing function of indirect, by RA pointer and GDB tool, the memory application situation of function can be shown without wasting excess resource, for the memory orientation problem of embedded system, the positioning time for greatly shortening memory leak issue, improve development efficiency.

Description

A kind of general method for detecting memory leakage
Technical field
The present invention relates to memory leak detecting fields, and in particular to a kind of general method for detecting memory leakage.
Background technique
Memory overflow is the comparison stubborn problem frequently encountered in process of embedded system exploitation, and usual way is logical It crosses addition type information to go to debug, cumbersome, inefficient, the progress of serious obstruction project of orientation problem.Also have Method is the memory service condition by record thread, but it is abnormal and interior quickly to position some thread memory application Depositing application is also likely to be to discharge in another thread, and it is not fully accurate to count.
For example, application No. is CN201710211056.5, a kind of entitled method for detecting memory leakage and equipment are disclosed When application program is run on a virtual machine, Java Virtual Machine tool interface JVMTI is called to monitor whether that there are objects to be recovered; Wherein the object is associated with identifier;Monitor be recovered there are object in the case where, deleted in default set described in The associated identifier of object;Wherein the default set includes multiple objects respectively associated identifier;Determine the default collection Object associated by one or more identifiers in conjunction in remaining identifier is RAM leakage object.And application No. is CN201510136216.5, the detection method and device of entitled RAM leakage disclose the memory to system according to user instructions It is squeezed, the anonymous memory of target program is swapped out to swapace;During the target program continues to run, connect Receive the memory access request of the target program;By the corresponding memory change of the memory access request, and record the interior of change The memory information deposited;The memory information of the memory of the change of record is counted and is carried out with the leakage point to RAM leakage Positioning;Wherein, the memory information of the memory of the change of described pair of record is counted is clicked through with the leakage to RAM leakage Row positioning, comprising: the call chain of the target program is generated according to the memory information of the memory of the change, and to the calling The frequency of occurrence of chain is counted and is sorted, so that realizing the leak point to RAM leakage by the content of the call chain Positioning.But above-mentioned scheme is without solving the technical problem to be solved in the invention.
Summary of the invention
In order to solve above-mentioned insufficient defect, the present invention provides a kind of general method for detecting memory leakage, the present invention By way of recording RA pointer, the title for remembeing function of indirect can show function by RA pointer and GDB tool Memory application situation without waste excess resource memory is greatly shortened for the memory orientation problem of embedded system The positioning time of leakage problem, improve development efficiency.
The present invention provides a kind of general method for detecting memory leakage, comprising the following steps:
Step (1): by the embedded assembly code for obtaining RA pointer of malloc/free, RA pointer value is recorded;
Step (2): after malloc memory application success, address is recorded in array;When free discharges successfully, By the record purge in array;
Step (3): the data of buffer area are classified using RA, are counted to the application of each identical RA pointer.
Above-mentioned detection method, wherein specifically include in the step (2): record application is returned after application memory success The pointer address returned, removes the RA pointer and pointer address of record after discharging successfully.
Above-mentioned detection method, wherein the step (3) specifically includes:
Step (3.1): when memory is checked in user's input order, memory explicit function is called;
Step (3.2): the data of buffer area are classified using RA, calculate the big of the secondary application by the pointer value of record It is small;
Step (3.3): the application of each identical RA pointer is counted and is printed;
Step (3.4):, can quick positioning question using GDB tool by the RA pointer value of printing.
Above-mentioned detection method, wherein in the step (2) after malloc memory application success, address is recorded in It is specifically included in array: searching the storage space subscript being not used by the area MemCallerInfo using find-addr (0); Then RA pointer and application are successfully stored in buffer area.
Above-mentioned detection method, wherein in the step (2) when free discharges successfully, by the record purge in array Specifically include: using find-addr (Addr) search will the pointer address that be released whether in the buffer area MemCallerInfo, Then RA pointer and the successful address of application are removed from buffer area.
The present invention provides a kind of general method for detecting memory leakage to have the advantages that the present invention passes through record The mode of RA pointer, the title for remembeing function of indirect can show the memory Shen of function by RA pointer and GDB tool Please situation without waste excess resource memory leak issue is greatly shortened for the memory orientation problem of embedded system Positioning time, improve development efficiency.
Detailed description of the invention
Upon reading the detailed description of non-limiting embodiments with reference to the following drawings, the present invention and its feature, outer Shape and advantage will become more apparent upon.Identical label indicates identical part in all the attached drawings.Not deliberately proportionally Draw attached drawing, it is preferred that emphasis is show the gist of the present invention.
Fig. 1 is a kind of flow diagram of general method for detecting memory leakage of the present invention.
Fig. 2 is the local flow diagram in a kind of general method for detecting memory leakage of the present invention.
Fig. 3 is in the present invention when developer inputs meminfo order, the step schematic diagram that can be executed.
Specific embodiment
In the following description, a large amount of concrete details are given so as to provide a more thorough understanding of the present invention.So And it is obvious to the skilled person that the present invention may not need one or more of these details and be able to Implement.In other examples, in order to avoid confusion with the present invention, for some technical characteristics well known in the art not into Row description.
In order to thoroughly understand the present invention, detailed step and detailed structure will be proposed in following description, so as to Illustrate technical solution of the present invention.Presently preferred embodiments of the present invention is described in detail as follows, however other than these detailed descriptions, this Invention can also have other embodiments.
The general method for detecting memory leakage of one kind provided by the invention, which comprises the following steps:
Step (1): by the embedded assembly code for obtaining RA pointer of malloc/free, RA pointer value is recorded;
Step (2): after malloc memory application success, address is recorded in array;When free discharges successfully, By the record purge in array, the pointer address that specially record application returns after application memory success, after discharging successfully Remove the RA pointer and pointer address of record;And after malloc memory application success, address is recorded in array and is had Body includes: to search the storage space subscript being not used by the area MemCallerInfo using find-addr (0);Then RA is referred to Needle and application are successfully stored in buffer area;When free discharges successfully, the record purge in array is specifically included: being used Find-addr (Addr) search will the pointer address that be released whether in the buffer area MemCallerInfo, then by RA pointer and Apply for that successful address is removed from buffer area.That is meminfo order is inputted by serial ports, by all application record values It prints.During printing, array is traversed, identical RA pointer is classified as one kind, it is then successfully first by application Address calculation goes out the size applied, and summation is calculated.The advantages of way, is only kept a record in malloc without appointing What data processing, so as not to time course and influence system operation, the whole ability in meminfo order execution of all data processings It executes.
Step (3): the data of buffer area are classified using RA, count, have to the application of each identical RA pointer Body includes:
Step (3.1): when memory is checked in user's input order, memory explicit function is called;
Step (3.2): the data of buffer area are classified using RA, calculate the big of the secondary application by the pointer value of record It is small;
Step (3.3): the application of each identical RA pointer is counted and is printed;
Step (3.4):, can quick positioning question using GDB tool by the RA pointer value of printing.
It is convenient that the present invention provides for memory leak positioning problem in systems development process, during debugging, by opening macro control Switch can input meminfo order in console and check Installed System Memory use information, when a problem occurs, can quickly determine Position problem, improves development efficiency.
In the present invention since system starting, application information is just recorded when there is memory application;When user inputs meminfo Afterwards, the memory information explicit function in meminfo is executed;Memory information explicit function traverses the number of entire stored memory information Group, by identical RA pointer statistic of classification, the number of each RA pointer application of final output and the memory of application are always for small;Pass through GDB debugging tool, can quick mapping function title using RA pointer.By with record RA register value and according to starting point Location, which is found, applies for that two means of block size can solve existing program and the plenty of time is needed to transplant, and encapsulation is difficult, and following range has The defects of limit, fundamentally thoroughly comprehensive solution memory overflow significant deficiency.
Embodiment 1
It is shown in reference picture 1, Fig. 2, a kind of general method for detecting memory leakage, comprising the following steps:
Eembedded Assembly instructs in application/releasing memory function malloc/free, obtains the RA pointer currently called. The pointer address that record application returns after application memory success, RA pointer and the pointer of record are removed after discharging successfully Location.When user inputs order and checks memory, memory explicit function is called, the data of buffer area are classified using RA, pass through note The pointer value of record calculates the size of the secondary application, and then the application of each identical RA pointer is counted and printed, The operation only executes the processing of data after user inputs order, only successful to RA pointer and application in malloc Pointer address saves, and ensure that the efficiency of kernel.By the RA pointer value of printing, it can quickly be positioned and be asked using GDB tool Topic, the present embodiment is by way of recording RA pointer, the title for remembeing function of indirect, by RA pointer and GDB tool, i.e., It can show that the memory application situation of function without wasting excess resource, greatly shortens the positioning time of memory leak issue, Improve development efficiency.
Presently preferred embodiments of the present invention is described above.It is to be appreciated that the invention is not limited to above-mentioned Particular implementation, devices and structures not described in detail herein should be understood as gives reality with the common mode in this field It applies;Anyone skilled in the art, without departing from the scope of the technical proposal of the invention, all using the disclosure above Methods and technical content many possible changes and modifications are made to technical solution of the present invention, or be revised as equivalent variations etc. Embodiment is imitated, this is not affected the essence of the present invention.Therefore, anything that does not depart from the technical scheme of the invention, foundation Technical spirit of the invention any simple modifications, equivalents, and modifications made to the above embodiment, still fall within the present invention In the range of technical solution protection.

Claims (5)

1. a kind of general method for detecting memory leakage, which comprises the following steps:
Step (1): by the embedded assembly code for obtaining RA pointer of malloc/free, RA pointer value is recorded;
Step (2): after malloc memory application success, address is recorded in array;When free discharges successfully, will count Record purge in group;
Step (3): the data of buffer area are classified using RA, are counted to the application of each identical RA pointer.
2. a kind of general method for detecting memory leakage as described in claim 1, which is characterized in that tool in the step (2) Body includes: the pointer address that record application returns after application memory success, removed after discharge successfully the RA pointer of record with Pointer address.
3. a kind of general method for detecting memory leakage as claimed in claim 2, which is characterized in that the step (3) is specific Include:
Step (3.1): when memory is checked in user's input order, memory explicit function is called;
Step (3.2): the data of buffer area are classified using RA, and the size of the secondary application is calculated by the pointer value of record;
Step (3.3): the application of each identical RA pointer is counted and is printed;
Step (3.4):, can quick positioning question using GDB tool by the RA pointer value of printing.
4. general method for detecting memory leakage as claimed in claim 3 a kind of, which is characterized in that in the step (2) when After malloc memory application success, address is recorded in array and is specifically included: searched using find-addr (0) The storage space subscript being not used by the area MemCallerInfo;Then RA pointer and application are successfully stored in buffer area.
5. general method for detecting memory leakage as claimed in claim 4 a kind of, which is characterized in that in the step (2) when When free is discharged successfully, the record purge in array is specifically included: searching the finger that will be released using find-addr (Addr) Then RA pointer and the successful address of application are removed from buffer area whether in the buffer area MemCallerInfo needle address.
CN201910131891.7A 2019-02-22 2019-02-22 A kind of general method for detecting memory leakage Pending CN109933525A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201910131891.7A CN109933525A (en) 2019-02-22 2019-02-22 A kind of general method for detecting memory leakage

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201910131891.7A CN109933525A (en) 2019-02-22 2019-02-22 A kind of general method for detecting memory leakage

Publications (1)

Publication Number Publication Date
CN109933525A true CN109933525A (en) 2019-06-25

Family

ID=66985833

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201910131891.7A Pending CN109933525A (en) 2019-02-22 2019-02-22 A kind of general method for detecting memory leakage

Country Status (1)

Country Link
CN (1) CN109933525A (en)

Citations (10)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101539870A (en) * 2008-03-21 2009-09-23 中兴通讯股份有限公司 Device and method for detecting memory leak
CN101814049A (en) * 2010-03-23 2010-08-25 北京大学 Memory leak detection method
CN101908018A (en) * 2010-07-20 2010-12-08 北京海泰方圆科技有限公司 System and method for judging memory leak
CN103455424A (en) * 2013-09-18 2013-12-18 哈尔滨工业大学 Dynamic internal memory leakage detecting method and device based on VxWorks operation system
CN105260314A (en) * 2015-11-03 2016-01-20 上海斐讯数据通信技术有限公司 Memory leak monitoring method
CN105912458A (en) * 2016-03-28 2016-08-31 中国电力科学研究院 Method and system for dynamically detecting C/C++ memory leak
CN106502880A (en) * 2016-09-20 2017-03-15 东软集团股份有限公司 A kind of memory overflow adjustment method and device
CN106610892A (en) * 2015-10-23 2017-05-03 腾讯科技(深圳)有限公司 Memory leak detecting method and device
CN106919454A (en) * 2017-01-25 2017-07-04 福建三元达网络技术有限公司 Memory pool positioning problems method and its system based on LTE protocol stack
CN109325353A (en) * 2018-11-01 2019-02-12 南京邮电大学 A kind of cluster leak analysis method for home router

Patent Citations (10)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101539870A (en) * 2008-03-21 2009-09-23 中兴通讯股份有限公司 Device and method for detecting memory leak
CN101814049A (en) * 2010-03-23 2010-08-25 北京大学 Memory leak detection method
CN101908018A (en) * 2010-07-20 2010-12-08 北京海泰方圆科技有限公司 System and method for judging memory leak
CN103455424A (en) * 2013-09-18 2013-12-18 哈尔滨工业大学 Dynamic internal memory leakage detecting method and device based on VxWorks operation system
CN106610892A (en) * 2015-10-23 2017-05-03 腾讯科技(深圳)有限公司 Memory leak detecting method and device
CN105260314A (en) * 2015-11-03 2016-01-20 上海斐讯数据通信技术有限公司 Memory leak monitoring method
CN105912458A (en) * 2016-03-28 2016-08-31 中国电力科学研究院 Method and system for dynamically detecting C/C++ memory leak
CN106502880A (en) * 2016-09-20 2017-03-15 东软集团股份有限公司 A kind of memory overflow adjustment method and device
CN106919454A (en) * 2017-01-25 2017-07-04 福建三元达网络技术有限公司 Memory pool positioning problems method and its system based on LTE protocol stack
CN109325353A (en) * 2018-11-01 2019-02-12 南京邮电大学 A kind of cluster leak analysis method for home router

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
周立功: "SOPC嵌入式系统基础教程", 《SOPC嵌入式系统基础教程 *

Similar Documents

Publication Publication Date Title
CN106610892B (en) Memory leak detection method and device
US8141053B2 (en) Call stack sampling using a virtual machine
CN106933733B (en) Method and device for determining memory leak position
US7930491B1 (en) Memory corruption detection system and method using contingency analysis regulation
CN107066390B (en) Dynamic memory leak detection method and system
US9003240B2 (en) Blackbox memory monitoring with a calling context memory map and semantic extraction
US6523141B1 (en) Method and apparatus for post-mortem kernel memory leak detection
US8132051B2 (en) Method and system for sampling input data
CN105912458A (en) Method and system for dynamically detecting C/C++ memory leak
CN101478481B (en) Buffer management method and apparatus, data forwarding system
CN112035314B (en) Memory leakage monitoring method and device and electronic equipment
CN110647472A (en) Breakdown information statistical method and device, computer equipment and storage medium
US7996658B2 (en) Processor system and method for monitoring performance of a selected task among a plurality of tasks
US20240095174A1 (en) Method for detecting error of operating system kernel memory in real time
CN111813666A (en) Memory leak positioning method, device, medium and electronic equipment
JP2012503825A (en) Memory management technology that uses selective mitigation to reduce errors
KR100965426B1 (en) Memory Leak Detecting Apparatus and Method thereof
CN110704303A (en) Method and device for acquiring test coverage information
CN107526970A (en) The method of bug when being run based on binary detection of platform
CN108667740A (en) The method, apparatus and system of flow control
CN112965845A (en) Delay analysis method, electronic device, and storage medium
CN109933525A (en) A kind of general method for detecting memory leakage
CN117149644A (en) Memory overflow detection method, device, operating system, equipment and storage medium
CN113127314A (en) Method and device for detecting program performance bottleneck and computer equipment
CN111858307B (en) Fuzzy test method and equipment

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
RJ01 Rejection of invention patent application after publication

Application publication date: 20190625

RJ01 Rejection of invention patent application after publication