Interprocess memory leak detection method and system based on high-order function abstract
By analyzing the memory operation behavior and performing inter-process analysis based on the high-order function summary method, the problem of low memory leak detection efficiency in the existing technology is solved, and efficient detection of various memory leak situations is achieved.
Patent Information
- Application Number
- CN202410595743.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-05-14
- Publication Date
- 2024-08-23
AI Technical Summary
Existing memory leak detection technology cannot cover multiple memory leak situations at the same time. In particular, the detection efficiency of memory leaks caused by inter-procedural function calls is low, and the traditional method to construct graphs is complex, resulting in low analysis efficiency.
An inter-procedure memory leak detection method based on high-order function summary is used to analyze memory operation behavior by generating function call graphs and control flow graphs, generate function summaries, and perform inter-procedure analysis through the correspondence between formal parameters and actual parameters to detect memory leakage.
It improves the efficiency of memory leak detection and can detect a variety of memory leak situations, including ordinary unreleased, different paths, pointer assignments, pointer calculations and memory management function mismatches, etc., reducing the space overhead during the analysis process and enhancing detection. Accuracy.
Smart Images

Figure CN118535467A
Abstract
Description
Technical Field
[0001] The invention belongs to the field of functional programming and program analysis, and in particular relates to an inter-procedural memory leak detection method and system based on high-order function summaries. Background Art
[0002] Memory leak defects are a type of omission defect that is common in programs written in languages that require manual memory release (such as C, C++). Due to negligence or improper design when developers write code, it is impossible to obtain effective access to the memory space before the memory is released, so the memory space cannot be released, and this block of memory can no longer be used. Memory leak failures in programs usually cause serious problems. If they are not managed, they will gradually consume memory resources. This is more obvious when the program is running for a long time, and the performance is that the application runs slower and slower, and in severe cases, it may crash due to insufficient memory.
[0003] There are many classifications of memory leaks, which can be divided into the following situations: (1) Ordinary non-release. This means that memory is applied for in a function but not returned to the system, causing a memory leak. (2) Different paths. Memory leaks are caused by different execution paths due to loops or conditional statements. It may also be that the path is too complicated or the function returns early. (3) Pointer assignment. This means reassigning the only pointer that owns the memory, causing it to lose ownership of the original memory, thereby causing the original memory block to leak. (4) Pointer calculation. This means performing illegal operations on pointers, resulting in incomplete memory release and partial leakage. (5) Memory management function mismatch. This means that the functions used to apply for and release memory are inconsistent. For example, the malloc function is used to apply for memory space, but delete is used instead of free when releasing it. The memory space cannot be released correctly, thus causing a memory leak.
[0004] Existing memory leak detection technologies usually cannot cover the above five situations at the same time, and traditional methods are not efficient in detecting memory leaks caused by inter-procedural function calls. Context-sensitive analysis is usually achieved by constructing various graphs. Due to the large size of the graphs and the complexity of the composition process, the analysis efficiency is low and there are a lot of redundant calculations. Summary of the invention
[0005] In view of the deficiencies in the prior art, the purpose of the present invention is to provide an inter-procedural memory leak detection method and system based on high-order function summaries, which solves the problems in the prior art.
[0006] The purpose of the present invention can be achieved by the following technical solutions:
[0007] An inter-procedural memory leak detection method based on high-order function summary includes the following steps:
[0008] S1, generate the function call graph and control flow graph of the program to be tested, determine the function analysis order, and build the collection used in the analysis process;
[0009] S2, taking out a function according to the function analysis sequence, traversing the control flow graph of the function, analyzing the statements related to the memory operation behavior therein, and generating a function summary;
[0010] S3, for the function call statement, substitute the information of the actual parameters at the call point into the function summary of the called function, and then pass the instantiated summary result back to the call point according to the correspondence between the formal parameters and the actual parameters. Continue to analyze the calling function according to the instantiated information and perform inter-procedural analysis:
[0011] S4, determine whether all functions have been analyzed. If not, go to S2 to continue the analysis. If all functions have been analyzed, output a memory leak defect detection report and the process ends.
[0012] Furthermore, the set constructed in S1 includes:
[0013] Pointer variable set P m , represents the set of all pointer variables pointing to memory block m;
[0014] Allocation set alloc, a tuple<p,a> , a∈A, A represents the function or operator used when allocating memory, which is used to check whether the memory management function matches;
[0015] Release set free, which is a triple<p,f,flag> ,f∈F, F represents the memory release method; flag is used to identify whether the memory has been released; p represents the pointer variable in the release statement;
[0016] Mapping relationship map, which is a triple<m,alloc,free> , m represents a memory block;
[0017] Pointer memory mapping set pms, which stores the mapping relationship map between pointers and memory blocks;
[0018] And, the function summary Sum, which is a two-tuple <P m ,annotation>, annotation is a behavior annotation. When a formal parameter or global variable is encountered, a lambda expression with the formal parameter or global variable as a parameter is generated and added to P m In collection.
[0019] Furthermore, the memory operation behavior includes: memory allocation behavior, memory release behavior and memory transfer behavior;
[0020] The analysis corresponding to the memory allocation behavior is: generating a new mapping relationship map, and updating the pointer memory mapping set pms;
[0021] The analysis corresponding to the memory release behavior is: updating the free set in the mapping relationship map, and updating the pointer memory mapping set pms;
[0022] The analysis corresponding to the memory transfer behavior is: update the pointer variable set P m , and update the pointer memory mapping set pms.
[0023] Furthermore, the memory transfer behavior refers to: a change in a pointer variable pointing to a memory space, including: pointer assignment and pointer calculation;
[0024] The pointer assignment is: For the assignment statement p=q, the operation is as follows:
[0025] ① If p and q point to the same memory space, the set does not change;
[0026] ② If p and q point to different pointers, let p point to m1 and q point to m2. After executing the assignment statement, delete the variable p from the pointer variable set of m1 and add it to the pointer variable set of m2.
[0027] The pointer calculation is as follows: for a pointer operation statement, the pointer variable is directly deleted from the pointer variable set of the memory it points to. If the pointer is used to release memory space afterwards, it will be considered a memory leak.
[0028] Furthermore, the specific steps of generating the function summary include:
[0029] For variables such as function parameters and global variables whose final information cannot be determined due to function calls, they are replaced with specific symbols during the analysis process, and then lambda expressions with these specific symbols as parameters are generated to represent pointer variables pointing to memory block m; the generated lambda expressions are used as parameters in the current function summary;
[0030] Generate annotation behavior annotations, which mainly provide an abstract description of the memory operation behavior within the function.
[0031] Furthermore, generating annotation behavior annotations includes the following situations:
[0032] 1) If an object goes through the entire process from allocation to release within a function, this behavior is not recorded;
[0033] 2) If an object has memory allocated in a function but not released, and the object is returned or is an external object, this behavior is recorded: annotation =<AllocFromExtern,A> , A represents the function or operator used in memory allocation;
[0034] 3) If an external object returns the memory space originally requested in a function, this behavior is recorded: annotation =<ExternToFree,F,flag> , F represents the function or operator used when releasing memory, and flag indicates whether the memory has been released;
[0035] 4) If the final state of an object within a function is a memory leak, the behavior is not documented, but a memory leak defect is reported.
[0036] An inter-procedural memory leak detection system based on high-order function summaries, comprising:
[0037] Program preprocessing module: generates the function call graph and control flow graph of the program to be tested, determines the function analysis order, and constructs the collection used in the analysis process;
[0038] In-process analysis module: taking out a function according to the function analysis sequence, traversing the control flow graph of the function, analyzing the statements related to the memory operation behavior, and generating a function summary;
[0039] Interprocedural analysis module: For function call statements, the information of the actual parameters at the call point is substituted into the function summary of the called function. Then, according to the correspondence between the formal parameters and the actual parameters, the instantiated summary result is passed back to the call point. The calling function is further analyzed based on the instantiated information to perform interprocedural analysis:
[0040] And, the detection module: determines whether all functions have been analyzed. If not, it switches to the intra-process analysis module for further analysis; if all functions have been analyzed, it outputs a memory leak defect detection report and the process ends.
[0041] A computer storage medium stores a readable program, which can execute the above-mentioned inter-procedural memory leak detection method based on high-order function summary when the program is running.
[0042] An electronic device, comprising: a processor, a memory, a communication interface and a communication bus, wherein the processor, the memory and the communication interface communicate with each other through the communication bus;
[0043] The memory is used to store at least one executable instruction, and the executable instruction enables the processor to perform operations corresponding to the above-mentioned inter-procedural memory leak detection method based on high-order function summary.
[0044] A computer program product includes computer instructions, wherein the computer instructions instruct a computing device to execute operations corresponding to the above-mentioned inter-procedural memory leak detection method based on high-order function summary.
[0045] Beneficial effects of the present invention:
[0046] 1. This method uses the characteristics of high-order functions to obtain memory allocation and release information within the process, and generates a function summary expressed in the form of a high-order function. This can facilitate the substitution of (high-order) function parameters in the function summary at the call point when calling between processes, and quickly obtain the correspondence between formal parameters and actual parameters. Compared with traditional summary-based analysis methods, the parameters in the high-order function summary of this method can not only be expressed as a specific value, but also as a function. It can carry more information during parameter passing, and thus can effectively improve the efficiency of memory leak detection between programs.
[0047] 2. Compared with the traditional graph-reachable method, this method does not need to construct various hypergraphs, avoiding the problem of low analysis efficiency due to the huge graph and complex composition process. Therefore, it can effectively reduce the space overhead in the analysis process and improve the efficiency of inter-process memory leak detection without losing detection accuracy.
[0048] 3. This method can detect the five memory leaks mentioned in the background technology. In addition, it can also detect double release errors in the program. Compared with the existing memory leak technology, this method covers a wider range of memory errors. BRIEF DESCRIPTION OF THE DRAWINGS
[0049] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, for ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.
[0050] Figure 1 is a flow chart of inter-procedural memory leak detection based on high-order function summary of the present invention;
[0051] Figure 2 It is a detailed flow chart of inter-procedural memory leak detection based on high-order function summary of the present invention. DETAILED DESCRIPTION
[0052] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0053] It should be noted that higher-order functions are one of the core concepts of functional programming. They are widely supported and applied in many programming languages and can also be used in other programming paradigms. A higher-order function is a function that can receive a function as a parameter or return a new function. A higher-order function that returns a new function can be used to create closures or implement decorator-like functions. A typical example is to add additional logic or functionality before and after a function is executed. Using higher-order functions in programming can also enhance the flexibility and reusability of the code. For example, a function can be passed as a parameter to a higher-order function so that the function can be called in different contexts. Doing so can make the code more concise and readable, and allow the same higher-order function to be applied to different needs.
[0054] like Figure 1 and Figure 2 As shown, a method for detecting inter-procedural memory leaks based on high-order function summaries includes the following steps:
[0055] S1, program preprocessing: generate the function call graph and control flow graph of the program to be tested, determine the function analysis order, and build the collection used in the analysis process;
[0056] The specific steps of program preprocessing include:
[0057] S11, generating a function call graph and a control flow graph of the program to be tested;
[0058] In this embodiment, the selected program codes to be detected are shown in Table 1:
[0059] Table 1 Memory leak detection sample code
[0060]
[0061] S12, traversing the function call graph in the order of reverse topological sorting to determine the function analysis order;
[0062] In this embodiment, the function analysis order is qux->bar->foo. (Since there is no calling relationship between function qux and function bar, the analysis order of the two functions can be swapped.)
[0063] S13, construct set P m, alloc, free, map, pms, Sum, their meanings are as follows:
[0064] ①Pointer variable set P m , represents the set of all pointer variables pointing to memory block m;
[0065] ②Allocation set alloc, in the form of a tuple<p,a> , a∈A, each allocated memory in the program has an allocation set. m It indicates the set of all pointer variables pointing to the memory block m; A indicates the function or operator used in memory allocation, which is mainly used to check whether the memory management function matches. A={a malloc ,a new ,a new[]}, a malloc Indicates that the allocation statement uses the malloc, calloc, realloc and other allocation functions in the C language. new and a new[] It means that the allocation statement uses the new function and new[] function in C++ respectively;
[0066] ③ Release set free, in the form of a triple<p,f,flag> ,f∈F, each allocated memory in the program has a release set, and the value is empty when it is not released. Among them, F represents the memory release method, F={f free ,f del ,f del[]}, f free Indicates that the release statement uses the free function in C language, f del and f del[] It means that the release statement uses the delete function and delete[] function in C++, which are mainly used to check whether the memory management keyword or function matches; flag is used to identify whether the memory has been released, flag =
[0067] {False,True}, the initial value is False, mainly used to check whether it is a double release; p represents the pointer variable in the release statement, if p∈P m , flag = False, and the allocation function matches the release function, then m can be released correctly;
[0068] ④Mapping relationship map, in the form of a triple<m,alloc,free> Among them, m represents a memory block. Since it is only necessary to know that a storage unit is allocated to detect memory leaks without considering its specific address, the subscript can be used to distinguish different heap address units. The subscript can be set to an increasing variable, such as m1, m2, etc.;
[0069] ⑤Pointer memory mapping set pms, which stores the mapping relationship map between pointers and memory blocks;
[0070] ⑥ Function summary Sum, in the form of a tuple <P m ,annotation>, where annotation is the behavior annotation, P m Represents a set of pointer variables pointing to memory block m. When a formal parameter or global variable is encountered, a lambda expression with the formal parameter or global variable as a parameter is generated and added to P m In collection.
[0071] S2, intra-procedural analysis: Take out a function according to the function analysis sequence determined in S1, traverse the control flow graph of the function, analyze the statements related to memory operation behaviors, update the results of the corresponding set, and then generate the function summary of the function; and represent the function parameters and global variables with specific symbols as parameters of the current function summary, so as to substitute the actual parameters for instantiation later;
[0072] The steps of the in-process analysis include:
[0073] S21, taking out a function according to the function analysis order determined in S12, and traversing the control flow graph of the function;
[0074] S22, analyzing the statements related to the memory operation behavior.
[0075] The memory operation behavior includes: memory allocation behavior, memory release behavior and memory transfer behavior;
[0076] S221, the analysis corresponding to the memory allocation behavior is: generating a new mapping relationship map, and updating the pointer memory mapping set pms. The memory allocation behavior refers to obtaining memory space through a memory allocation function (new, malloc, etc.);
[0077] S222, the analysis corresponding to the memory release behavior is: updating the free set in the mapping relationship map, and updating the pointer memory mapping set pms. The memory release behavior refers to using the memory release function (delete, free, etc.) to release the memory space;
[0078] S223, the analysis corresponding to the memory transfer behavior is: update the pointer variable set P m , and update the pointer memory mapping set pms. Among them, the memory transfer behavior refers to: the pointer variable pointing to the memory space changes; including:
[0079] (1) Pointer assignment: For example, the assignment statement p = q, its operation is as follows:
[0080] ① If p and q point to the same memory space, the set does not change;
[0081] ②If p and q point to different points, let p point to m1 and q point to m2. After executing the assignment statement, delete the variable p from the pointer variable set of m1 and add it to the pointer variable set of m2.
[0082] (2) Pointer calculation: When performing operations on pointers, the first address of the memory space pointed to by the pointer will change. If the pointer is used to release the memory space, it will cause partial memory leakage. Therefore, for pointer operation statements, directly delete the pointer variable from the pointer variable set of the memory it points to. If the pointer is used to release the memory space later, it will be considered a memory leak.
[0083] When the pointer variable set of a certain memory space is empty and no memory release behavior is found in the free set, it means that the memory space can no longer be operated, which means that the memory cannot be released, that is, there is a memory leak defect; when a certain memory space has been released (that is, flag = True in the free set of the memory block), if a memory release statement is encountered again to try to release the memory space, there is a double release defect. The defect information is stored in the test report in the form of<Func,Line,error> ,error∈ERROR, where Func represents the function name, Line represents the line number, ERROR={e ml ,e df}, indicating the error type, e ml and e df Indicates memory leak errors and double free errors respectively.
[0084] S23, judging whether all the statements have been analyzed, if not, then go to S22 to continue the analysis; if all the statements have been analyzed, then go to S24;
[0085] S24, generating a function summary Sum according to the pms set of the function;
[0086] The specific steps to generate a function summary include:
[0087] S241, for variables such as function parameters and global variables whose final information cannot be determined due to function calls, specific symbols (Greek letters such as α and β) are used to replace them during the analysis process, and then λ expressions with these specific symbols as parameters are generated to represent pointer variables pointing to the memory block m. The generated λ expression is used as a parameter in the current function summary so that the actual parameters can be substituted later to update the analysis results;
[0088] Assume that variables a and b are parameters or global variables of the function Func. In the function summary to Func, the corresponding Pm When adding these variables to the set, they are replaced by a lambda expression of the form λαλβ.P(α,β), where P(α,β) is the analysis result of the pointer variable set corresponding to the function parameters. The lambda expression can represent a specific value or a function. When the corresponding actual parameter is encountered, the lambda expression is instantiated to obtain an accurate result.
[0089] S242, generate annotation behavior annotation, annotation mainly abstractly describes the memory operation behavior within the function.
[0090] There are several situations in which annotation behavior annotations are generated:
[0091] 1) If an object goes through the complete process from allocation to release within a function, this behavior is not recorded.
[0092] 2) If an object has memory allocated in a function but not released, and the object is returned or is an external object, this behavior is recorded: annotation =<AllocFromExtern,A> , for the convenience of representation, AllocFromExtern is abbreviated as AFE; A represents the function or operator used when allocating memory;
[0093] 3) If an external object returns the originally requested memory space in a function, this behavior is recorded: annotation =<ExternToFree,F,flag> For the convenience of representation, ExternToFree is abbreviated as ETF; F represents the function or operator used when releasing the memory, and flag indicates whether the memory has been released;
[0094] 4) If the final state of an object within a function is a memory leak, the behavior is not documented, but a memory leak defect is reported.
[0095] In this embodiment, for the qux function, its pointer memory mapping set
[0096] , the function ends and returns the pointer variable p. For the calling function, p is an external variable, so it is replaced by the parameter α. According to the situation 2 in S242, the function summary Sum={(λα.qux(α), <AFE,a malloc >)}.
[0097] In this embodiment, the pointer memory mapping set of the bar function pms = {(m,alloc, <p,f free, False>)}, p is its formal parameter, so it is replaced by parameter α, according to the situation 3 in step S242, the function summary Sum={(λα.bar(α), <ETF,f free ,False>)}.
[0098] S3, inter-procedural analysis: for function call statements, the information of actual parameters at the call point is substituted into the function summary of the called function, and then the instantiated summary result is passed back to the call point according to the correspondence between formal parameters and actual parameters, and the calling function is further analyzed according to the instantiated information;
[0099] The steps of interprocedural analysis include:
[0100] S31, obtaining actual parameters at the call point;
[0101] S32, substituting the obtained actual parameter into the corresponding parameter of the called function summary to instantiate the function summary;
[0102] S33, the instantiated function summary analysis result is transmitted back to the call point, the pointer memory mapping set pms is updated according to the instantiated information, and the analysis is continued in S23.
[0103] In this embodiment, for the foo function, the analysis process is as follows:
[0104] At line 10, the function pointer memory map is set
[0105] In line 11, a memory space m1 is requested and received by the pointer variable p, so at this time the pointer memory mapping set
[0106] In line 12, the qux function is called and assigned to the pointer variable q. Then the variable q is used to instantiate the function summary of qux, and Sum = {({q}, <AFE,a malloc >)} and returns to the calling point, at which point the pointer memory mapping set
[0107] Line 13 is a pointer assignment statement. From the pointer assignment in S223, we can see that the pointer memory mapping set is
[0108]
[0109] Since the pointer variable set in map1 is empty at this time, and its free set is also empty, the memory space m1 is leaked, and defect information is generated. <foo,13,e ml >, stored in the test report;
[0110] In line 14, the bar function is called and the actual parameter q is passed in. Then the variable q is used to instantiate the function summary of bar, and Sum = {{q}, <ETF,f free ,False>)} and pass it back to the calling site, at which point the pointer memory map set
[0111] Since q∈{p,q}, flag=False and the allocation function matches the release function, the memory space m2 is correctly released and there is no memory leak.
[0112] S4, determine whether all functions have been analyzed. If not, go to S2 to continue the analysis. If all functions have been analyzed, output a memory leak defect detection report and the process ends.
[0113] In this embodiment, all functions are analyzed and a memory leak detection report is output.
[0114] <foo,13,e ml >, which means that a memory error occurs in function foo, specifically located at line 13, and the error type is a memory leak.
[0115] The method of the present embodiment may be implemented in hardware, firmware, or as software or computer code that can be stored in a recording medium (such as a CDROM, RAM, floppy disk, hard disk, or magneto-optical disk), or as computer code that is originally stored in a remote recording medium or a non-temporary machine-readable medium downloaded over a network and will be stored in a local recording medium, so that the method described herein can be stored in such software processing on a recording medium using a general-purpose computer, a dedicated processor, or programmable or dedicated hardware (such as an ASIC or FPGA). It is understood that a computer, a processor, a microprocessor controller, or programmable hardware includes a storage component (e.g., RAM, ROM, flash memory, etc.) that can store or receive software or computer code, and when the software or computer code is accessed and executed by a computer, a processor, or hardware, the method described herein is implemented. In addition, when a general-purpose computer accesses the code for implementing the method shown herein, the execution of the code converts the general-purpose computer into a dedicated computer for executing the method shown herein.
[0116] The above shows and describes the basic principles, main features and advantages of the present invention. Those skilled in the art should understand that the present invention is not limited to the above embodiments, and the above embodiments and descriptions are only for explaining the principles of the present invention. Without departing from the spirit and scope of the present invention, the present invention may have various changes and improvements, and these changes and improvements all fall within the scope of the present invention to be protected.
Claims
1. A method for detecting inter-procedural memory leaks based on high-order function summaries, characterized in that: The following steps are involved: S1, generate the function call graph and control flow graph of the program to be tested, determine the function analysis order, and build the collection used in the analysis process; S2, taking out a function according to the function analysis sequence, traversing the control flow graph of the function, analyzing the statements related to the memory operation behavior therein, and generating a function summary; S3, for the function call statement, substitute the information of the actual parameters at the call point into the function summary of the called function, and then pass the instantiated summary result back to the call point according to the correspondence between the formal parameters and the actual parameters. Continue to analyze the calling function according to the instantiated information and perform inter-procedural analysis: S4, determine whether all functions have been analyzed. If not, go to S2 to continue the analysis. If all functions have been analyzed, output a memory leak defect detection report and the process ends.
2. The method for detecting inter-procedural memory leaks based on high-order function summaries according to claim 1, characterized in that: The collections constructed in S1 include: Pointer variable set P m , represents the set of all pointer variables pointing to memory block m; Allocation set alloc, a tuple<p,a> , a∈A, A represents the function or operator used when allocating memory, which is used to check whether the memory management function matches; Release set free, which is a triple<p,f,flag> ,f∈F, F represents the memory release method; flag is used to identify whether the memory has been released; p represents the pointer variable in the release statement; Mapping relationship map, which is a triple<m,alloc,free> , m represents a memory block; Pointer memory mapping set pms, which stores the mapping relationship map between pointers and memory blocks; And, the function summary Sum, which is a two-tuple <P m ,annotation>, annotation is a behavior annotation. When a formal parameter or global variable is encountered, a lambda expression with the formal parameter or global variable as a parameter is generated and added to P m In collection.
3. The method for detecting inter-procedural memory leaks based on high-order function summaries according to claim 2, characterized in that: The memory operation behavior includes: memory allocation behavior, memory release behavior and memory transfer behavior; The analysis corresponding to the memory allocation behavior is: generating a new mapping relationship map, and updating the pointer memory mapping set pms; The analysis corresponding to the memory release behavior is: updating the free set in the mapping relationship map, and updating the pointer memory mapping set pms; The analysis corresponding to the memory transfer behavior is: update the pointer variable set P m , and update the pointer memory mapping set pms.
4. The method for detecting inter-procedural memory leaks based on high-order function summaries according to claim 3, characterized in that: The memory transfer behavior refers to: the pointer variable pointing to the memory space changes, including: pointer assignment and pointer calculation; The pointer assignment is: For the assignment statement p=q, the operation is as follows: ① If p and q point to the same memory space, the set does not change; ② If p and q point to different pointers, let p point to m1 and q point to m2. After executing the assignment statement, delete the variable p from the pointer variable set of m1 and add it to the pointer variable set of m2. The pointer calculation is as follows: for a pointer operation statement, the pointer variable is directly deleted from the pointer variable set of the memory it points to. If the pointer is used to release memory space afterwards, it will be considered a memory leak.
5. The method for detecting inter-procedural memory leaks based on high-order function summaries according to claim 4, characterized in that: The specific steps of generating the function summary include: For variables such as function parameters and global variables whose final information cannot be determined due to function calls, they are replaced with specific symbols during the analysis process, and then lambda expressions with these specific symbols as parameters are generated to represent pointer variables pointing to memory block m; the generated lambda expressions are used as parameters in the current function summary; Generate annotation behavior annotations, which mainly provide an abstract description of the memory operation behavior within the function.
6. The method for detecting inter-procedural memory leaks based on high-order function summaries according to claim 5, characterized in that: Generating annotation behavior annotations includes the following situations: 1) If an object goes through the entire process from allocation to release within a function, this behavior is not recorded; 2) If an object has memory allocated in a function but not released, and the object is returned or is an external object, this behavior is recorded: annotation =<AllocFromExtern,A> , A represents the function or operator used in memory allocation; 3) If an external object returns the memory space originally requested in a function, this behavior is recorded: annotation =<ExternToFree,F,flag> , F represents the function or operator used when releasing memory, and flag indicates whether the memory has been released; 4) If the final state of an object within a function is a memory leak, the behavior is not documented, but a memory leak defect is reported.
7. An inter-procedural memory leak detection system based on high-order function summaries, characterized in that: include: Program preprocessing module: generates the function call graph and control flow graph of the program to be tested, determines the function analysis order, and constructs the collection used in the analysis process; In-process analysis module: taking out a function according to the function analysis sequence, traversing the control flow graph of the function, analyzing the statements related to the memory operation behavior, and generating a function summary; Interprocedural analysis module: For function call statements, the information of the actual parameters at the call point is substituted into the function summary of the called function. Then, according to the correspondence between the formal parameters and the actual parameters, the instantiated summary result is passed back to the call point. The calling function is further analyzed based on the instantiated information to perform interprocedural analysis: And, the detection module: determines whether all functions have been analyzed. If not, it switches to the intra-process analysis module for further analysis; if all functions have been analyzed, it outputs a memory leak defect detection report and the process ends.
8. A computer storage medium storing a readable program, characterized in that: When the program is running, the inter-procedural memory leak detection method based on high-order function summary described in any one of claims 1 to 6 can be executed.
9. An electronic device, comprising: A processor, a memory, a communication interface and a communication bus, wherein the processor, the memory and the communication interface communicate with each other via the communication bus; The memory is used to store at least one executable instruction, and the executable instruction enables the processor to perform operations corresponding to the inter-procedural memory leak detection method based on high-order function summary as described in any one of claims 1-6.
10. A computer program product, comprising computer instructions, wherein the computer instructions instruct a computing device to execute operations corresponding to the inter-procedural memory leak detection method based on high-order function summary as described in any one of claims 1-6.
