Memory leak detection method and device, electronic equipment and storage medium

By injecting the memory management interface into the target program and collecting resource data, generating statistical charts to identify abnormal functions, the accuracy and efficiency of existing memory leak detection methods are solved, and efficient memory leak detection is achieved.

CN119473671APending Publication Date: 2025-02-18CHINA TELECOM CORP LTD TECHNOLOGY INNOVATION CENTER +1
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411499099.4
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-10-25
Publication Date
2025-02-18

AI Technical Summary

Technical Problem

The existing memory leak detection methods have accuracy and efficiency problems. Static detection is prone to missed false alarms, while dynamic detection tools are expensive and complex in deployment, making it difficult to deploy on a large scale in actual scenarios.

Method used

By reading environment variables and associated program link libraries, determine the memory management interface of the target program and inject it into the target program. During the operation of the target program, resource data of each process is collected, statistical charts of memory allocation data and function call frequency data are generated, and exception functions and their corresponding memory leak code segments are identified.

Benefits of technology

It improves the accuracy and efficiency of memory leak detection, without the need to deploy a large number of dynamic detection tools, and can comprehensively and in detail the exception functions of memory usage exceptions in the target program and locate their corresponding memory leak code segments.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119473671A_ABST
    Figure CN119473671A_ABST
Patent Text Reader

Abstract

The invention discloses a memory leak detection method and device, electronic equipment and a storage medium, and relates to the technical field of network security. The method comprises the steps of determining a memory management interface used by a target program according to a read environment variable and a program link library associated with the environment variable; injecting the memory management interface into the target program, and collecting resource data of each process in the running process of the target program; respectively generating a first statistical graph and a second statistical graph according to the resource data of each process; wherein the first statistical graph is used for displaying memory allocation data of functions contained in each process in the target program; the second statistical graph is used for displaying accumulated frequency data of calling of functions contained in each process; and according to the first statistical graph and the second statistical graph, determining an abnormal function in each function, and determining a memory leak code segment corresponding to the abnormal function in the target program.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of network security technology, and in particular to a memory leak detection method, device, electronic device and storage medium. Background Art

[0002] As software scale and complexity continue to increase, memory leaks have become a major factor affecting program reliability and have attracted much attention. Memory leaks refer to the failure or inability to release dynamically allocated heap memory in a program for some reason, resulting in a waste of system memory, slowing down program execution, or even causing system crashes and other serious consequences.

[0003] Existing memory leak detection methods are mainly divided into static detection and dynamic detection. Among them, static detection refers to the use of static code analysis tools to statically analyze the source code to find potential memory leak problems; dynamic detection refers to the use of dynamic detection tools to monitor the memory usage of the program during runtime to find potential memory leak problems.

[0004] However, the above-mentioned static detection method is limited by the detection mechanism, and there are often problems such as missed reports and false positives in the detection results. The dynamic detection tool used in the dynamic detection method has a high performance overhead, which will affect the running performance of the program. At the same time, its deployment method is complicated and cannot be deployed on a large scale in actual scenarios. Summary of the invention

[0005] The present application provides a memory leak detection method, device, electronic device and storage medium to improve the accuracy and efficiency of memory leak detection.

[0006] In a first aspect, a memory leak detection method is provided, comprising:

[0007] Determine the memory management interface used by the target program according to the read environment variable and the program link library associated with the environment variable;

[0008] Injecting the memory management interface into the target program, and collecting resource data of each process during the running of the target program;

[0009] Generating a first statistical graph and a second statistical graph respectively according to the resource data of each process; wherein the first statistical graph is used to display the memory allocation data of the functions respectively contained in each process in the target program; and the second statistical graph is used to display the cumulative frequency data of the functions respectively contained in each process being called;

[0010] According to the first statistical graph and the second statistical graph, an abnormal function is determined in each function, and a memory leak code segment corresponding to the abnormal function in the target program is determined.

[0011] In an embodiment of the present application, first, based on the read environment variables and the program link library associated with the environment variables, the memory management interface used by the target program is determined, the memory management interface is injected into the target program, and during the operation of the target program, the resource data of each process is collected; then, according to the resource data of each process, a first statistical graph and a second statistical graph are generated respectively, the first statistical graph is used to display the memory allocation data of the functions contained in each process of the target program, so as to facilitate a more intuitive understanding of the memory usage of each function; the second statistical graph is used to display the cumulative frequency data of the functions contained in each process being called, so as to facilitate a more intuitive understanding of which functions are called too frequently, resulting in a waste of memory resources; then, according to the first statistical graph and the second statistical graph, the abnormal function is determined in each function, and the memory leakage code segment corresponding to the abnormal function in the target program is determined, without using and deploying a large number of dynamic detection tools, the abnormal function with abnormal memory usage in the target program can be comprehensively and detailed detected, and the specific memory leakage code segment corresponding to the abnormal function can be located, thereby improving the accuracy and efficiency of memory leak detection.

[0012] In some embodiments, collecting resource data for each process includes:

[0013] Collecting memory allocation data of functions contained in each process, and counting cumulative frequency data of functions contained in each process being called;

[0014] The memory allocation data and the accumulated frequency data are output to a log file.

[0015] In some embodiments, determining an abnormal function in each function according to the first statistical graph and the second statistical graph includes:

[0016] If in the first statistical graph, it is determined that the memory allocation data of the first function is greater than the first set threshold, and in the second statistical graph, it is determined that the cumulative frequency data of the first function being called is greater than the second set threshold, then the first function is determined to be an abnormal function.

[0017] In some embodiments, the target program is written using the CORE mechanism.

[0018] In some embodiments, the memory allocation data includes at least the memory address, memory size, and stack backtrace information of each function when applying for and releasing memory.

[0019] In some embodiments, the second statistical graph is also used to display the amount of memory requested by each function and the amount of memory released by each function.

[0020] In a second aspect, a memory leak detection device is provided, comprising:

[0021] A determination module, used to determine a memory management interface used by a target program according to the read environment variables and a program link library associated with the environment variables;

[0022] A collection module, used to inject the memory management interface into the target program and collect resource data of each process during the operation of the target program;

[0023] A generating module, used to generate a first statistical graph and a second statistical graph respectively according to the resource data of each process; wherein the first statistical graph is used to display the memory allocation data of the functions respectively contained in each process in the target program; and the second statistical graph is used to display the cumulative frequency data of the functions respectively contained in each process being called;

[0024] The detection module is used to determine an abnormal function in each function according to the first statistical graph and the second statistical graph, and determine a memory leak code segment corresponding to the abnormal function in the target program.

[0025] According to a third aspect, an electronic device is provided, including:

[0026] A memory for storing a computer program; a processor for implementing any one of the method steps in the first aspect when executing the computer program stored in the memory.

[0027] According to a fourth aspect, a computer-readable storage medium is provided, wherein a computer program is stored in the computer-readable storage medium, and when the computer program is executed by a processor, the method steps described in any one of the first aspects are implemented.

[0028] For each aspect from the second to the fourth aspect and the technical effects that may be achieved by each aspect, please refer to the above description of the technical effects that can be achieved by the first aspect or various possible schemes in the first aspect, and no further details will be given here. BRIEF DESCRIPTION OF THE DRAWINGS

[0029] Figure 1 A schematic diagram of an application scenario applicable to the embodiments of the present application;

[0030] Figure 2 A flowchart of a memory leak detection method provided in an embodiment of the present application;

[0031] Figure 3A logical schematic diagram of memory leak detection provided in an embodiment of the present application;

[0032] Figure 4 A schematic diagram of the structure of a memory leakage device provided in an embodiment of the present application;

[0033] Figure 5 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0034] In order to make the purpose, technical scheme and advantages of the present application clearer, the technical scheme in the embodiment of the present application will be clearly and completely described below in conjunction with the drawings in the embodiment of the present application. Obviously, the described embodiment is only a part of the embodiment of the present application, rather than all the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in the field without making creative work are within the scope of protection of the present application. In the absence of conflict, the embodiments in the present application and the features in the embodiments can be arbitrarily combined with each other. In addition, although the logical order is shown in the flow chart, in some cases, the steps shown or described can be performed in an order different from that here.

[0035] The terms "first" and "second" in the specification and claims of the present application and the above-mentioned drawings are used to distinguish different objects, rather than to describe a specific order. In addition, the term "comprising" and any of their variations are intended to cover non-exclusive protection. For example, a process, method, system, product or device comprising a series of steps or units is not limited to the listed steps or units, but optionally also includes steps or units that are not listed, or optionally also includes other steps or units inherent to these processes, methods, products or devices. "Multiple" in the present application can mean at least two, for example, two, three or more, and the embodiments of the present application are not limited.

[0036] The following is a description of exemplary embodiments of the present application in conjunction with the accompanying drawings, including various details of the embodiments of the present application to facilitate understanding, which should be considered as merely exemplary. Therefore, those of ordinary skill in the art should recognize that various changes and modifications can be made to the embodiments described herein without departing from the scope of the present application. Similarly, for the sake of clarity and conciseness, the description of well-known functions and structures is omitted in the following description. It should be noted that in the embodiments of the present application, certain software, components, models and other existing solutions in the industry may be mentioned, which should be considered as exemplary, and their purpose is only to illustrate the feasibility of the implementation of the technical solution of the present application, but it does not mean that the applicant has or will necessarily use the solution.

[0037] In order to better understand the embodiments of the present application, the technical terms involved in the embodiments of the present application are first explained below.

[0038] (1) A process is the basic unit of resource allocation and scheduling. A thread is the execution unit in a process. A function is the basic unit of thread execution. A process can include multiple threads at the same time.

[0039] (2) Memory allocation is to store the data and variables needed for program execution. Memory release means returning the block of memory to the operating system after the program has completed its use.

[0040] (3) Environment variables refer to some parameters used in the operating system to specify the operating environment of the operating system, such as the location of temporary folders and system folders, etc. It contains information that will be used by one or more programs.

[0041] (4) Extended Berkeley Packet Filter (eBPF) is an efficient program running in the kernel that is used to monitor and analyze operating system events, especially network traffic and system calls.

[0042] (5) The Compile Once-Run Everywhere (CORE) mechanism allows eBPF programs to run on different kernel versions and configurations without recompiling.

[0043] (6) The uprobe probe is a dynamic tracing mechanism provided by the kernel that allows users to insert probes at specific locations in user-mode programs to monitor and collect program behavior and data while the program is running.

[0044] The following briefly introduces the application scenarios to which the technical solutions of the embodiments of the present application can be applied. It should be noted that the application scenarios introduced below are only used to illustrate the embodiments of the present application and are not limited. In specific implementation, the technical solutions provided by the embodiments of the present application can be flexibly applied according to actual needs.

[0045] Figure 1 Schematic diagram of an application scenario applicable to the embodiment of the present application. As shown in the figure, the application scenario mainly includes: a terminal 10 and a server 11. Among them, information exchange can be performed between the terminal 10 and the server 11 through a communication network, and the communication mode adopted by the communication network may include: a wireless communication mode and a wired communication mode.

[0046] In some scenarios, the terminal 10 can access the network and communicate with the server 11 through cellular mobile communication technology, and the cellular mobile communication technology may include the fifth generation mobile communication (5th Generation Mobile Networks, 5G) technology and the future 6G technology.

[0047] In some scenarios, the terminal 10 may access the network and communicate with the server 11 via short-range wireless communication. The short-range wireless communication may include Wireless Fidelity (Wi-Fi) technology.

[0048] The present application embodiment does not impose any restriction on the number of the above-mentioned devices. Figure 1 As shown, only the terminal 10 and the server 11 are described as examples, and the above-mentioned devices and their respective functions are briefly introduced below.

[0049] The terminal 10 is a device that can provide voice and / or data connectivity to the user, including: a handheld terminal device with a wireless connection function, a vehicle-mounted terminal device, etc. For example, the terminal 10 includes but is not limited to: a mobile phone, a tablet computer, a laptop computer, a PDA, a mobile Internet device (Mobile Internet Device, MID), a wearable device, a virtual reality (Virtual Reality, VR) device, an augmented reality (Augmented Reality, AR) device, a wireless terminal device in industrial control, a wireless terminal device in unmanned driving, a wireless terminal device in a smart grid, a wireless terminal device in transportation safety, a wireless terminal device in a smart city, or a wireless terminal device in a smart home, etc.

[0050] In addition, a client related to memory leak detection may be installed on the terminal 10, and the client may be software (e.g., an APP, a browser, etc.), or a web page, a small program, etc. In the embodiment of the present application, the terminal 10 may use the above-mentioned client related to memory leak, and may interact with the server 11 to perform memory leak detection in the program.

[0051] In some scenarios, server 11 can be an independent physical server, a server cluster or distributed system composed of multiple physical servers, or a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, content delivery networks (CDN), as well as big data and artificial intelligence platforms.

[0052] Furthermore, in an embodiment of the present application, the server 11 may be equipped with a memory leak detection device corresponding to the client, and the memory leak detection device is used to quickly and accurately detect abnormal functions with abnormal memory usage in the program, and locate the specific memory leak code segment corresponding to the abnormal function.

[0053] To further illustrate the technical solution provided by the embodiment of the present application, this is described in detail below in conjunction with the accompanying drawings and specific implementation methods. Although the embodiment of the present application provides the method operation steps as shown in the following embodiments or drawings, more or fewer operation steps may be included in the method based on routine or no creative labor. In the steps where there is no necessary causal relationship logically, the execution order of these steps is not limited to the execution order provided by the embodiment of the present application. The method may be executed or executed in parallel in the actual processing process or when the device is executed in accordance with the method sequence shown in the embodiment or drawings.

[0054] Figure 2 A flowchart of a memory leak detection method provided in an embodiment of the present application. The process can be executed by a memory leak detection device, which can be implemented by software and / or hardware to improve the accuracy and efficiency of memory leak detection. Figure 2 As shown, the process includes the following steps:

[0055] 201: Determine the memory management interface used by the target program according to the read environment variable and the program link library associated with the environment variable.

[0056] In some embodiments, the target program (which may refer to the eBPF program) is compiled using the CORE mechanism, and the target program can be deployed to any terminal, so that the target program has the advantages of high portability and reliability. For example, the CORE mechanism is used to compile the eBPF program to generate a program that can be deployed on a terminal (such as Figure 1 The binary file is loaded and run on the terminal 10) shown in the figure, and then the compiled eBPF program and necessary configuration files are deployed to the terminal, and the terminal can run the eBPF program.

[0057] In some embodiments, the memory management interface used by the target program is determined based on the read environment variables and the program link library associated with the environment variables. The method may be: reading the environment variables in the target program, and determining the actual program link library in the target program based on the information provided in the environment variables (such as the path or name of the library file). The program link library may include a static link library (.lib or .a file) or a dynamic link library (.dll, .so or .dylib file). After determining the program link library, the memory management link library related to memory management (such as the malloc library) can be searched. It usually refers to a set of functions and methods for implementing memory allocation, recovery, protection and other functions, as well as determining the memory management interface used by the target program, so that the functions and methods in the memory management link library can be called through these memory management interfaces to implement memory management.

[0058] 202: Inject the above memory management interface into the target program, and collect resource data of each process while the target program is running.

[0059] In some embodiments, uprobe probes may be used to collect resource data for each process.

[0060] In some embodiments, collecting resource data for each process may include: collecting memory allocation data for functions contained in each process, and counting cumulative frequency data of calls to functions contained in each process; and outputting the memory allocation data and cumulative frequency data to a log file.

[0061] Furthermore, the memory allocation data includes at least the memory address, memory size, and stack backtrace information of each function when applying for and releasing memory; wherein the memory address and memory size can be directly obtained from the injected memory management interface, and the stack backtrace information is used to indicate at which function and location the memory application and release occurred.

[0062] Furthermore, the cumulative frequency data of the functions contained in each process being called can be counted by: the cumulative frequency data of the functions contained in each process being called can be counted by a counter or a hash table. In other embodiments, the amount of memory applied by each function and the amount of memory released by each function can also be counted, so that the difference between the amount of memory applied and the amount of memory released by each function can be compared, so as to facilitate the subsequent determination based on this whether there is a function that has applied for memory but has not released the memory, resulting in a waste of memory resources.

[0063] Furthermore, the log file may include timestamp, process ID, thread ID, stack backtrace information, memory address and memory size of memory request, memory address and memory size of memory release, memory request amount, memory release amount, cumulative frequency of each function being called, etc.

[0064] In other embodiments, the resource data also includes CPU usage, etc., to facilitate subsequent comprehensive analysis.

[0065] 203: Generate a first statistical graph and a second statistical graph based on the resource data of each process, wherein the first statistical graph is used to display the memory allocation data of the functions contained in each process in the target program, and the second statistical graph is used to display the cumulative frequency data of the functions contained in each process being called.

[0066] In some embodiments, the second statistical graph is also used to display the amount of memory requested by each function and the amount of memory released by each function.

[0067] In some embodiments, a tool (such as flamegraph) can be used or a custom script can be written to generate the first statistical graph (which may be called a memory distribution flame graph) and the second statistical graph (which may be called a call stack heat map) to display the memory allocation of each function, the frequency of each function being called, and the cumulative amount of memory requested and released, thereby intuitively displaying the hot spots and flows of memory usage.

[0068] It should be noted that the display shape of the first statistical graph and the second statistical graph can be in the form of a tree diagram, a line graph, a bar graph, or a pie chart. The first statistical graph and the second statistical graph can be flexibly selected according to actual needs, and the embodiments of the present application do not limit this.

[0069] 204: According to the first statistical graph and the second statistical graph, an abnormal function is determined in each function, and a memory leak code segment corresponding to the abnormal function in the target program is determined.

[0070] In some embodiments, based on the above-mentioned first statistical graph and second statistical graph, an abnormal function is determined in each function, which can be: if in the first statistical graph, it is determined that the memory allocation data of the first function is greater than the first set threshold, and in the second statistical graph, it is determined that the cumulative frequency data of the first function being called is greater than the second set threshold, then the first function is determined to be an abnormal function.

[0071] For example, if in the first statistical graph, it is determined that the memory size of the first function (such as gnu_cxx new_allocator) is 353.6MB, accounting for 50.3% of the total memory, which is greater than the first set threshold (such as 30%), and in the second statistical graph, it is determined that the cumulative frequency data of the first function being called is 10 times, which is greater than the second set threshold (such as 6 times), then it indicates that the memory allocation amount of the first function is large and the resource overhead is too large, and the first function is determined to be an abnormal function.

[0072] In some embodiments, after determining the memory leak code segment corresponding to the abnormal function in the target program, the memory leak code segment can also be detected by troubleshooting tools (such as Valgrind, AddressSanitizer, etc.) or manual troubleshooting (for example, checking the implementation of the abnormal function to see if there is any unreleased memory allocation, etc.), to determine the specific cause of the memory leak code segment and the repair strategy. Among them, the repair strategy includes but is not limited to: releasing no longer needed memory resources, using smart pointers (such as std::unique_ptr, std::shared_ptr) to automatically manage memory, and for objects (functions) that are frequently allocated and released, you can consider using a memory pool to reduce memory fragmentation and allocation / release overhead.

[0073] In other embodiments, after determining the specific cause of the memory leak code segment and the repair strategy, the abnormal function can also be recorded, and the detailed information of memory application and release can be recorded to facilitate subsequent tracing and query.

[0074] In an embodiment of the present application, first, based on the read environment variables and the program link library associated with the environment variables, the memory management interface used by the target program is determined, the memory management interface is injected into the target program, and during the operation of the target program, the resource data of each process is collected; then, according to the resource data of each process, a first statistical graph and a second statistical graph are generated respectively, the first statistical graph is used to display the memory allocation data of the functions contained in each process of the target program, so as to facilitate a more intuitive understanding of the memory usage of each function; the second statistical graph is used to display the cumulative frequency data of the functions contained in each process being called, so as to facilitate a more intuitive understanding of which functions are called too frequently, resulting in a waste of memory resources; then, according to the first statistical graph and the second statistical graph, the abnormal function is determined in each function, and the memory leakage code segment corresponding to the abnormal function in the target program is determined, without using and deploying a large number of dynamic detection tools, the abnormal function with abnormal memory usage in the target program can be comprehensively and detailed detected, and the specific memory leakage code segment corresponding to the abnormal function can be located, thereby improving the accuracy and efficiency of memory leak detection.

[0075] Based on the above Figure 2The method shown, Figure 3 A logical schematic diagram of memory leak detection provided in an embodiment of the present application.

[0076] exist Figure 3 In the method, firstly, the memory management interface used by the target program is identified according to the read environment variables and the program link library associated with the environment variables, and the memory management interface is injected into the target program by using the uprobe probe, and during the operation of the target program, the resource data of each process is collected, and then the resource data collected in real time is periodically output to the log file; the log file is parsed, and a first statistical graph is generated according to the memory allocation data of the functions respectively contained in each process parsed, and a second statistical graph is generated according to the cumulative frequency data of the functions respectively contained in each process parsed; finally, according to the first statistical graph and the second statistical graph, the abnormal function is determined in each function, and the memory leak code segment corresponding to the abnormal function in the target program is determined.

[0077] Based on the same technical concept, an embodiment of the present application also provides a structural schematic diagram of a memory leak detection device, which can implement the above-mentioned memory leak detection method process in the embodiment of the present application.

[0078] Figure 4 The present invention provides a schematic diagram of a memory leak detection device according to an embodiment of the present invention. The device includes a determination module 401 , a collection module 402 , a generation module 403 , and a detection module 404 .

[0079] The determination module 401 is used to determine the memory management interface used by the target program according to the read environment variables and the program link library associated with the environment variables.

[0080] The collection module 402 is used to inject the memory management interface into the target program and collect resource data of each process during the operation of the target program.

[0081] The generation module 403 is used to generate a first statistical graph and a second statistical graph respectively according to the resource data of each process; wherein the first statistical graph is used to display the memory allocation data of the functions contained in each process in the target program; and the second statistical graph is used to display the cumulative frequency data of the functions contained in each process being called.

[0082] The detection module 404 is used to determine an abnormal function in each function according to the first statistical graph and the second statistical graph, and determine a memory leak code segment corresponding to the abnormal function in the target program.

[0083] In some embodiments, the collection module 402 is specifically configured to:

[0084] Collecting memory allocation data of functions contained in each process, and counting cumulative frequency data of functions contained in each process being called;

[0085] The memory allocation data and the accumulated frequency data are output to a log file.

[0086] In some embodiments, the detection module 404 is specifically configured to:

[0087] If in the first statistical graph, it is determined that the memory allocation data of the first function is greater than the first set threshold, and in the second statistical graph, it is determined that the cumulative frequency data of the first function being called is greater than the second set threshold, then the first function is determined to be an abnormal function.

[0088] It should be noted here that the above-mentioned device provided in the embodiment of the present application can implement all the method steps in the above-mentioned method embodiment and can achieve the same technical effect. The parts and beneficial effects of this embodiment that are the same as the method embodiment will not be described in detail here.

[0089] Based on the same technical concept, an electronic device is also provided in an embodiment of the present application, and the electronic device can realize the functions of the aforementioned memory leak detection device.

[0090] Figure 5 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application.

[0091] At least one processor 501, and a memory 502 connected to the at least one processor 501. The specific connection medium between the processor 501 and the memory 502 is not limited in the embodiment of the present application. Figure 5 In the example, the processor 501 and the memory 502 are connected via a bus 500. The bus 500 is Figure 5 The connections between other components are shown in bold lines, and are not intended to be limiting. The bus 500 can be divided into an address bus, a data bus, a control bus, etc. For ease of representation, Figure 5 Only one thick line is used in the figure, but it does not mean that there is only one bus or one type of bus. Alternatively, the processor 501 can also be called a controller, and there is no limitation on the name.

[0092] In the embodiment of the present application, the memory 502 stores instructions that can be executed by at least one processor 501. The at least one processor 501 can execute a memory leak detection method discussed above by executing the instructions stored in the memory 502. The processor 501 can implement Figure 4 The functions of each module in the device shown.

[0093] Among them, the processor 501 is the control center of the device, and can use various interfaces and lines to connect the various parts of the entire control device. By running or executing instructions stored in the memory 502 and calling data stored in the memory 502, the various functions of the device and processing data, the device can be monitored as a whole.

[0094] In the embodiment of the present application, the processor 501 may include one or more processing units, and the processor 501 may integrate an application processor and a modem processor, wherein the application processor mainly processes an operating system, a user interface, and application programs, and the modem processor mainly processes wireless communications. It is understandable that the modem processor may not be integrated into the processor 501. In some embodiments, the processor 501 and the memory 502 may be implemented on the same chip, and in some embodiments, they may also be implemented separately on separate chips.

[0095] The processor 501 may be a general-purpose processor, such as a central processing unit (CPU), a digital signal processor, an application-specific integrated circuit, a field programmable gate array or other programmable logic device, a discrete gate or transistor logic device, or a discrete hardware component, and may implement or execute the methods, steps, and logic block diagrams disclosed in the embodiments of the present application. A general-purpose processor may be a microprocessor or any conventional processor, etc. The steps of a memory leak detection method disclosed in the embodiments of the present application may be directly embodied as being executed by a hardware processor, or may be executed by a combination of hardware and software modules in the processor.

[0096] The memory 502 is a non-volatile computer-readable storage medium that can be used to store non-volatile software programs, non-volatile computer executable programs and modules. The memory 502 may include at least one type of storage medium, such as a flash memory, a hard disk, a multimedia card, a card-type memory, a random access memory (Random Access Memory, RAM), a static random access memory (Static Random Access Memory, SRAM), a programmable read-only memory (Programmable Read Only Memory, PROM), a read-only memory (Read Only Memory, ROM), an electrically erasable programmable read-only memory (Electrically Erasable Programmable Read-Only Memory, EEPROM), a magnetic memory, a disk, an optical disk, etc. The memory 502 is any other medium that can be used to carry or store a desired program code in the form of an instruction or data structure and can be accessed by a computer, but is not limited thereto. The memory 502 in the embodiment of the present application can also be a circuit or any other device that can realize a storage function, for storing program instructions and / or data.

[0097] By programming the processor 501, the code corresponding to the memory leak detection method described in the above embodiment can be fixed into the chip, so that the chip can execute the code when running. Figure 2 The embodiment shown is a memory leak detection method. How to design and program the processor 501 is a technique known to those skilled in the art and will not be described in detail here.

[0098] It should be noted here that the above-mentioned electronic device provided in the embodiment of the present application can implement all the method steps implemented in the above-mentioned method embodiment, and can achieve the same technical effect. The parts and beneficial effects of this embodiment that are the same as the method embodiment will not be described in detail here.

[0099] Based on the same technical concept, an embodiment of the present application provides a computer storage medium, the computer storage medium includes: a computer program code, when the computer program code is run on a computer, the computer executes any one of the memory leak detection methods discussed above. Since the principle of solving the problem by the above-mentioned computer storage medium is similar to that of a memory leak detection method, the implementation of the above-mentioned computer storage medium can refer to the implementation of the method, and the repeated parts will not be repeated.

[0100] In the specific implementation process, the computer storage medium may include: Universal Serial Bus Flash Drive (USB), mobile hard disk, read-only memory (ROM), random access memory (RAM), magnetic disk or optical disk, and other storage media that can store program codes.

[0101] Based on the same technical concept, the embodiment of the present application also provides a computer program product, which includes: computer program code, when the computer program code is run on a computer, the computer executes any one of the memory leak detection methods discussed above. Since the principle of solving the problem by the above computer program product is similar to that of a memory leak detection method, the implementation of the above computer program product can refer to the implementation of the method, and the repeated parts will not be repeated.

[0102] The computer program product may employ any combination of one or more readable media. The readable medium may be a readable signal medium or a readable storage medium. The readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination thereof. More specific examples (non-exhaustive list) of readable storage media include: an electrical connection with one or more conductors, a portable disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination thereof.

[0103] The method in the present application can be implemented in whole or in part by software, hardware, firmware or any combination thereof. When implemented by software, it can be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer programs or instructions. When the computer program or instruction is loaded and executed on a computer, the process or function described in the present application is executed in whole or in part. The computer can be a general-purpose computer, a special-purpose computer, a computer network, a network device, a user device, a core network device, an OAM or other programmable device.

[0104] The computer program or instructions may be stored in a computer-readable storage medium, or transmitted from one computer-readable storage medium to another computer-readable storage medium, for example, the computer program or instructions may be transmitted from one website, computer, server or data center to another website, computer, server or data center by wired or wireless means. The computer-readable storage medium may be any available medium that can be accessed by a computer or a data storage device such as a server or data center that integrates one or more available media. The available medium may be a magnetic medium, such as a floppy disk, a hard disk, or a magnetic tape; it may also be an optical medium, such as a digital video disk; it may also be a semiconductor medium, such as a solid-state drive. The computer-readable storage medium may be a volatile or non-volatile storage medium, or may include both volatile and non-volatile types of storage media.

[0105] Those skilled in the art will appreciate that the embodiments of the present application may be provided as methods, systems, or computer program products. Therefore, the present application may adopt the form of a complete hardware embodiment, a complete software embodiment, or an embodiment in combination with software and hardware. Moreover, the present application may adopt the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage and optical storage, etc.) that contain computer-usable program code.

[0106] The present application is described with reference to the flowcharts and / or block diagrams of the methods, devices (systems), and computer program products according to the embodiments of the present application. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 These computer program instructions can also be stored in a computer-readable memory that can guide a computer or other programmable data processing device to work in a specific manner, so that the instructions stored in the computer-readable memory produce a manufactured product including an instruction device, which implements the instructions in the process. Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.

[0107] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process in the computer or other programmable device. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.

[0108] Obviously, those skilled in the art can make various changes and modifications to the present application without departing from the spirit and scope of the present application. Thus, if these modifications and variations of the present invention fall within the scope of the claims of the present application and their equivalents, the present application is also intended to include these modifications and variations.

Claims

1. A memory leak detection method, characterized in that: include: Determine the memory management interface used by the target program according to the read environment variable and the program link library associated with the environment variable; Injecting the memory management interface into the target program, and collecting resource data of each process during the running of the target program; Generating a first statistical graph and a second statistical graph respectively according to the resource data of each process; wherein the first statistical graph is used to display the memory allocation data of the functions respectively contained in each process in the target program; and the second statistical graph is used to display the cumulative frequency data of the functions respectively contained in each process being called; According to the first statistical graph and the second statistical graph, an abnormal function is determined in each function, and a memory leak code segment corresponding to the abnormal function in the target program is determined.

2. The method according to claim 1, characterized in that The resource data collected for each process includes: Collecting memory allocation data of functions contained in each process, and counting cumulative frequency data of functions contained in each process being called; The memory allocation data and the accumulated frequency data are output to a log file.

3. The method according to claim 1, characterized in that Determining an abnormal function in each function according to the first statistical graph and the second statistical graph includes: If in the first statistical graph, it is determined that the memory allocation data of the first function is greater than the first set threshold, and in the second statistical graph, it is determined that the cumulative frequency data of the first function being called is greater than the second set threshold, then the first function is determined to be an abnormal function.

4. The method according to claim 1, characterized in that The target program is written using a compile-once-run-anywhere mechanism called CORE.

5. The method according to claim 1, characterized in that The memory allocation data at least includes the memory address, memory size, and stack backtrace information of each function when applying for and releasing memory.

6. The method according to claim 1, characterized in that The second statistical graph is also used to display the amount of memory requested by each function and the amount of memory released by each function.

7. A memory detection device, characterized in that: include: A determination module, used to determine a memory management interface used by a target program according to the read environment variables and a program link library associated with the environment variables; A collection module, used to inject the memory management interface into the target program and collect resource data of each process during the operation of the target program; A generating module, used to generate a first statistical graph and a second statistical graph respectively according to the resource data of each process; wherein the first statistical graph is used to display the memory allocation data of the functions respectively contained in each process in the target program; and the second statistical graph is used to display the cumulative frequency data of the functions respectively contained in each process being called; The detection module is used to determine an abnormal function in each function according to the first statistical graph and the second statistical graph, and determine a memory leak code segment corresponding to the abnormal function in the target program.

8. The device according to claim 7, characterized in that The collection module is specifically used for: Collecting memory allocation data of functions contained in each process, and counting cumulative frequency data of functions contained in each process being called; The memory allocation data and the accumulated frequency data are output to a log file.

9. An electronic device, characterized in that: include: Memory, used to store computer programs; A processor, configured to implement the method according to any one of claims 1 to 6 when executing a computer program stored in the memory.

10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the method according to any one of claims 1 to 6 is implemented.