Diagnostic positioning method and device for dynamic memory release abnormity, equipment and medium

By customizing the dynamic link library and making the environment variables of the application to be detected point to their path, the dynamic link library is called using the dynamic memory interface to record the thread ID, memory address and memory allocation size, the dynamic memory release exception detection in the existing technology is solved. The problem of poor matching performance achieves a high flexibility of abnormal detection effect.

CN119440896APending Publication Date: 2025-02-14GUOKE FOUNDATION STONE (CHONGQING) SOFTWARE CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411479732.3
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-10-22
Publication Date
2025-02-14

AI Technical Summary

Technical Problem

The prior art is difficult to effectively detect dynamic memory release exceptions during runtime in various application scenarios, and it requires the deployment of an open source environment, which has poor adaptability.

Method used

By customizing the dynamic link library, the environment variables of the application to be detected point to the path of the dynamic link library. The dynamic link library contains memory allocation functions and memory release functions. The dynamic link library is called through the dynamic memory interface to record the thread ID, memory address and Memory allocation size, and exception detection is achieved through memory data structure.

Benefits of technology

It realizes exception detection during memory allocation and release, avoids compilation and modification of the detection application, adapts to various application scenarios, and improves the flexibility and code reusability of dynamic memory release exception detection.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119440896A_ABST
    Figure CN119440896A_ABST
Patent Text Reader

Abstract

The invention relates to a diagnosis positioning method, device and equipment for dynamic memory release abnormity and a medium, and the method comprises the steps that a dynamic link library is customized, an environment variable of a to-be-detected application program points to a path of the dynamic link library, and the dynamic link library comprises a memory distribution function and a memory release function; and running the to-be-detected application program, calling the dynamic link library through a dynamic memory interface, positioning a dynamic memory release exceptional code, and outputting a positioning result. The dynamic memory allocation and release of the to-be-detected application program are realized by adopting the dynamic link library, so that the code reusability of the dynamic link library is high, the compiling modification of the to-be-detected application program is avoided, the exception detection in the memory allocation and release process is realized, and the method and the device can adapt to various application scenes, and are convenient to use. And the flexibility of dynamic memory release anomaly detection is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present disclosure relates to the field of memory management technology, and in particular to a method, device, electronic device and computer-readable storage medium for diagnosing and locating a dynamic memory release anomaly. Background Art

[0002] In the related art, dynamic memory release anomalies include memory leaks caused by forgetting to release dynamically allocated space, multiple releases of the same dynamic memory, etc., and dynamic memory release anomalies can cause system performance degradation or even crash. In the prior art, open source memory detection tools can be used to perform auxiliary analysis at runtime to determine the memory release situation, but the open source memory detection tool needs to be run in a separate open source environment; runtime memory detection can also be achieved by inserting code during compilation, but this method also requires the deployment of an open source environment and re-compilation with the memory detection tool before analysis can be performed, which is difficult to apply to a variety of customer environments.

[0003] Therefore, there is an urgent need for a method for diagnosing and locating dynamic memory release anomalies that can detect abnormal memory release at runtime and is suitable for a variety of application scenarios. Summary of the invention

[0004] In order to overcome the problems existing in the related art, the present disclosure provides a method, device, electronic device and computer-readable storage medium for diagnosing and locating a dynamic memory release anomaly.

[0005] According to a first aspect of an embodiment of the present disclosure, a method for diagnosing and locating a dynamic memory release anomaly is provided, comprising: customizing a dynamic link library and making the environment variable of an application to be detected point to the path of the dynamic link library, wherein the dynamic link library includes a memory allocation function and a memory release function; running the application to be detected, calling the dynamic link library through a dynamic memory interface, locating the code of the dynamic memory release anomaly, and outputting the locating result.

[0006] In some embodiments, the dynamic memory interface includes a dynamic memory application interface and a dynamic memory release interface. When dynamically allocating memory, the thread ID, memory address and memory allocation size are recorded through a memory data structure. When dynamically releasing memory, an error signal is generated by triggering the presence of a corresponding memory data structure to locate the code for dynamic memory release exceptions.

[0007] In some embodiments, when the dynamic link library is called through the dynamic memory application interface, it includes: calling the memory allocation function through the dynamic memory application interface to detect whether the resource usage is empty; if the resource usage is empty, initializing the resources through the built-in global static variables, and creating a memory data structure to perform dynamic memory allocation; if the resource usage is not empty, obtaining the current thread ID, memory address and memory allocation size, and writing them into the memory data structure to perform dynamic memory allocation.

[0008] In some embodiments, the creation of the memory data structure includes: obtaining the thread IDs of all threads, and performing a hash operation on the thread IDs to obtain an ID array; obtaining the memory block size corresponding to the thread according to the thread ID in the ID array, and constructing a memory block size array; based on the memory block size array, hashing the position information of memory blocks of the same size to obtain a position array; constructing a linked list based on memory blocks of the same size, and using the position array as the head node of the linked list to form a memory data structure.

[0009] In some embodiments, when the dynamic link library is called through the dynamic memory release interface, it includes: calling the memory release function through the dynamic memory release interface to obtain the thread ID and memory address of the thread to be released; according to the thread ID and memory address, searching whether the memory data structure corresponding to the thread to be released exists; if the corresponding memory data structure does not exist, the kernel generates an interrupt signal, completes the memory release exception detection, and outputs the positioning result according to the thread ID and memory address; if the corresponding memory data structure exists, the memory is released according to the memory address, and it is determined whether the memory data structure is empty; wherein, if the memory data structure is empty, the resources of the initial memory data structure in the dynamic link library are cleaned up; if the memory data structure is not empty, the memory data structure is released.

[0010] In some embodiments, outputting the positioning result according to the thread ID and the memory address includes: generating a core dump file according to the thread ID and the memory address, parsing it through GDB to form a call stack; and locating the exception code corresponding to the thread to be released according to the call stack.

[0011] In some embodiments, after creating the memory data structure, the method further includes: performing a locking operation on the memory data structure.

[0012] According to a second aspect of an embodiment of the present disclosure, a diagnostic positioning device for a dynamic memory release anomaly is provided, comprising: a dynamic link library customization module, used to customize the dynamic link library and make the environment variable of the application to be detected point to the path of the dynamic link library, wherein the dynamic link library includes a memory allocation function and a memory release function; a positioning result output module, used to run the application to be detected, call the dynamic link library through a dynamic memory interface, locate the code of the dynamic memory release anomaly, and output the positioning result.

[0013] According to a third aspect of an embodiment of the present disclosure, an electronic device is provided, comprising: a processor; a memory for storing executable instructions of the processor; the processor is used to read the executable instructions from the memory and execute the instructions to implement the diagnostic positioning method for dynamic memory release anomalies provided by the first aspect of the present disclosure.

[0014] According to a fourth aspect of an embodiment of the present disclosure, a computer-readable storage medium is provided, on which computer program instructions are stored. When the program instructions are executed by a processor, the steps of the method for diagnosing and locating dynamic memory release anomalies provided in the first aspect of the present disclosure are implemented.

[0015] The technical solution provided by the embodiments of the present disclosure may include the following beneficial effects: by customizing the dynamic link library and pointing the environment variable of the application to be detected to the path of the dynamic link library, the connection between the application to be detected and the dynamic link library is realized, and the dynamic link library includes a memory allocation function and a memory release function; running the application to be detected, calling the dynamic link library through the dynamic memory interface, locating the code of the dynamic memory release exception, outputting the positioning result, and using the dynamic link library to realize the dynamic memory allocation and release of the application to be detected, so that the code reusability of the dynamic link library is high, the compilation and modification of the application to be detected is avoided, the exception detection in the memory allocation and release process is realized, and it can adapt to various application scenarios, thereby improving the flexibility of dynamic memory release exception detection.

[0016] It is to be understood that the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the present disclosure. BRIEF DESCRIPTION OF THE DRAWINGS

[0017] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present disclosure and, together with the description, serve to explain the principles of the present disclosure.

[0018] Figure 1 The present invention is a flowchart of a method for diagnosing and locating a dynamic memory release anomaly according to an exemplary embodiment.

[0019] Figure 2It is a schematic diagram of APP static analysis and runtime analysis according to an exemplary embodiment.

[0020] Figure 3 The present invention is a flowchart of a method for calling a dynamic link library through a dynamic memory application interface according to an exemplary embodiment.

[0021] Figure 4 The topological structure diagram of a method for diagnosing and locating a dynamic memory release anomaly is shown according to an exemplary embodiment.

[0022] Figure 5 The invention is a flowchart of a method for creating a memory data structure according to an exemplary embodiment.

[0023] Figure 6 The figure is a schematic diagram of a process of creating a memory data structure according to an exemplary embodiment.

[0024] Figure 7 The present invention is a flowchart of a method for calling a dynamic link library through a dynamic memory release interface according to an exemplary embodiment.

[0025] Figure 8 The figure is a flowchart of a method for outputting a positioning result according to an exemplary embodiment.

[0026] Fig. 9 The invention is a block diagram showing a device for diagnosing and locating a dynamic memory release anomaly according to an exemplary embodiment.

[0027] Fig.10 It is a block diagram of an electronic device according to an exemplary embodiment. DETAILED DESCRIPTION

[0028] Exemplary embodiments will be described in detail below with reference to the accompanying drawings.

[0029] It should be pointed out that the relevant embodiments and drawings are only for describing exemplary embodiments provided by the present disclosure, rather than all embodiments of the present disclosure, and it should not be understood that the present disclosure is limited to the relevant exemplary embodiments.

[0030] It should be noted that the terms "first", "second", etc. used in the present disclosure are only used to distinguish different steps, devices or modules, etc. The related terms neither represent any specific technical meanings nor indicate the order or interdependence between them.

[0031] It should be noted that the modifications of the terms "one", "multiple", and "at least one" used in the present disclosure are illustrative rather than restrictive. Unless otherwise clearly indicated in the context, it should be understood as "one or more".

[0032] It should be noted that the term "and / or" used in this disclosure is used to describe the association relationship between associated objects, and generally indicates that there are at least three association relationships. For example, A and / or B can at least indicate the existence of three association relationships: A exists alone, A and B exist at the same time, and B exists alone.

[0033] It should be noted that the various steps described in the method embodiments of the present disclosure may be performed in different orders and / or in parallel. Unless otherwise specified, the scope of the present disclosure is not limited by the order of description of the steps in the relevant embodiments.

[0034] It should be noted that all actions of acquiring signals, information or data in the present disclosure are carried out in compliance with the relevant data protection laws and policies of the country where the device is located and with the authorization given by the owner of the corresponding device.

[0035] Exemplary Methods

[0036] Figure 1 is a flow chart showing a method for diagnosing and locating a dynamic memory release anomaly according to an exemplary embodiment. Figure 1 As shown, the diagnosis and positioning method of dynamic memory release exception is used for dynamic memory management, and includes the following steps:

[0037] In step S110, a dynamic link library is customized and the environment variable of the application to be detected is made to point to the path of the dynamic link library, wherein the dynamic link library includes a memory allocation function and a memory release function.

[0038] In one embodiment, a dynamic link library is customized, and the environment variable of the application to be detected is made to point to the path of the dynamic link library, thereby avoiding the compilation modification of the application to be detected. At runtime, the environment variable of the application to be detected can be made to point to the path of the dynamic link library, thereby improving the flexibility of dynamic memory abnormal release detection, and the dynamic link library allows multiple programs to share the same library file, saving system resources and facilitating update and maintenance. The dynamic link library includes a memory allocation function and a memory release function, so that the dynamic memory allocation running program dynamically allocates and releases memory as needed, thereby avoiding the waste and limitation of static memory allocation.

[0039] In step S120, the application to be detected is run, the dynamic link library is called through the dynamic memory interface, the code of the abnormal dynamic memory release is located, and the location result is output.

[0040] In one embodiment, after the application to be detected and the dynamic link library are connected, the application to be detected is run, the dynamic link library is called through the dynamic memory interface, the code of abnormal dynamic memory release is located, and the location result is output.

[0041] Specifically, abnormal dynamic memory release includes memory leaks, multiple memory releases, etc. Memory leaks mean that the dynamically allocated heap memory in the program is not released for some reason, which will cause memory waste and slow down the program running speed; multiple memory releases mean that the program uses the memory blocks that have been released, which may cause access conflicts or crashes.

[0042] Among them, the dynamic memory interface includes a dynamic memory application interface and a dynamic memory release interface. When dynamically allocating memory, the thread ID, memory address and memory allocation size are recorded through the memory data structure. When dynamically releasing memory, an error signal is generated by triggering the corresponding memory data structure to locate the code for dynamic memory release exceptions.

[0043] Specifically, the dynamic memory interface includes a dynamic memory application interface and a dynamic memory release interface, which are respectively used for dynamic memory allocation and dynamic memory release; when performing dynamic memory allocation, a memory data structure is used to record the thread ID, memory address and memory allocation size to perform corresponding memory allocation; when performing dynamic memory release, an error signal is generated by triggering the presence of a corresponding memory data structure to locate the abnormal code for dynamic memory release, so as to facilitate the processing of the abnormal code.

[0044] In the above embodiment, a dynamic link library is customized, and the environment variable of the application to be detected is pointed to the path of the dynamic link library, so as to realize the connection between the application to be detected and the dynamic link library, and the dynamic link library includes a memory allocation function and a memory release function; the application to be detected is run, and the dynamic link library is called through the dynamic memory interface to locate the code of the dynamic memory release exception, and the positioning result is output, and the dynamic link library is used to realize the dynamic memory allocation and release of the application to be detected, so that the code of the dynamic link library is highly reusable, and the compilation and modification of the application to be detected is avoided, and the exception detection in the memory allocation and release process is realized, and it can adapt to various application scenarios, thereby improving the flexibility of dynamic memory release exception detection.

[0045] In one embodiment, Figure 2 As shown, the DDS application is used as an example for explanation, but it is not limited to the application of DDS. The same is true for other applications. The user App does not need to make any changes. According to user needs, customize the code implemented by the dynamic link library. If all memblock sizes are tracked, no modification is required; customize the result output method, exportLD_PRELOAD = the path of the dynamic link library before running, and then run the user App to get the output result.

[0046] When using the dynamic memory release anomaly diagnosis and positioning method disclosed in the present invention, no changes are required in the compilation of the user program, and only the environment variables need to be exported during runtime, which only affects the interface of dynamic memory application and release, and has no effect on other functions.

[0047] This method can be used in a variety of scenarios: First, this method can be easily used on-site, and can accurately locate the location of the abnormal code during runtime. When there are strict requirements on the use environment, such as the user's online environment, online debugging is not possible, and offline reproduction is not possible, it can also diagnose and locate the abnormal release of dynamic memory during runtime. Second, this method can also be used in the test environment, by customizing and modifying various test cases and adapting automation tools to analyze the test results. Third, when used in DDS, it can achieve accurate grasp of the dynamic usage of each thread. Fourth, this method can also be used to determine resources that have not been released in time, which is convenient for dynamic memory usage analysis when the system is running.

[0048] Figure 3 is a flowchart of a method for calling a dynamic link library through a dynamic memory application interface according to an exemplary embodiment. Figure 3 As shown, the method of calling the dynamic link library through the dynamic memory application interface is used in step S120, including the following steps:

[0049] In step S210, a memory allocation function is called through a dynamic memory application interface to detect whether resource usage is empty.

[0050] Specifically, Figure 4 As shown, after connecting the dynamic link library and the dynamic memory application interface, when the application to be detected allocates memory, the dynamic memory application interface is used to call the memory allocation function of the dynamic link library. In order to avoid resource waste and optimize resource allocation, it is necessary to detect whether the resource usage (memory data structure) is empty and determine whether there is any memory that has not been released, so as to timely understand the current status of resource usage, thereby optimizing resource allocation and improving system performance and stability. The user application and DDS middleware call other dynamic memory interface functions in the same way. It should be noted that if it is necessary to distinguish between memory leaks and multiple releases, it is necessary to continue to determine whether there is any memory that has not been released, which is not required for normal program debugging.

[0051] In step S220, if the resource usage is empty, the resources are initialized through the built-in global static variables, and a memory data structure is created to perform dynamic memory allocation.

[0052] Specifically, when it is detected that the resource usage is empty, the resource is initialized through the built-in global static variable global staticbool, the resources of the data structure in the dynamic link library are cleaned up, and a memory data structure is created to perform dynamic memory allocation according to the created memory data structure.

[0053] In step S230, if the resource usage is not empty, the current thread ID, memory address and memory allocation size are obtained and written into the memory data structure to perform dynamic memory allocation.

[0054] Specifically, when it is detected that the resource usage is not empty, it means that the resources have been initialized, and the current thread ID, memory address and memory allocation size are directly obtained and written into the corresponding memory data structure to realize dynamic memory allocation and realize instant allocation according to the needs of the program. When allocating, the malloc function can be called to complete the memory allocation, thereby effectively realizing dynamic memory allocation and management, and ensuring the stability and efficiency of the program.

[0055] In this embodiment, when dynamic memory allocation is performed, the memory allocation function is called through the dynamic memory application interface to detect whether the resource usage is empty, so as to optimize resource configuration and improve system performance and stability; when the resource usage is empty, the resources are initialized through the built-in global static variables, and a memory data structure is created to perform dynamic memory allocation; when the resource usage is not empty, the current thread ID, memory address and memory allocation size are obtained, written into the memory data structure, and dynamic memory allocation is performed; thereby effectively controlling dynamic memory allocation and management to ensure the stability and efficiency of the program.

[0056] Figure 5 is a flowchart of a method for creating a memory data structure according to an exemplary embodiment. Figure 5 As shown, the method for creating a memory data structure is used in step S220, and includes the following steps:

[0057] In step S310, the thread IDs of all threads are obtained, and a hash operation is performed on the thread IDs to obtain an ID array.

[0058] Specifically, when creating an in-memory data structure, such as Figure 6 As shown, the thread IDs of all threads of the program to be detected are obtained, and the thread IDs are hashed to obtain an ID array, hash thread ID Index1...hash thread ID Indexn. The thread ID is mapped to a fixed hash value through the hash operation as the unique identifier of the thread, which facilitates fast search and management of the thread. The hash thread ID is a numeric type. Since the thread ID is normally generated continuously, the hash method can directly take the modulus 100.

[0059] In step S320, the memory block size corresponding to the thread is obtained according to the thread ID in the ID array, and a memory block size array is constructed.

[0060] Specifically, according to the thread ID in the ID array, the memory block size corresponding to the thread is obtained, and a memory block size array is constructed. For example, according to the thread ID hash thread ID Index 1, an array of different memory sizes memBlocksize a...memBlock size c is obtained to ensure continuous storage and efficient access of the array in memory.

[0061] In step S330, based on the memory block size array, hash processing is performed on the location information of the memory blocks of the same size to obtain a location array.

[0062] Specifically, based on the memory block size array, memory blocks of the same size are obtained, and the location information of the memory blocks of the same size is hashed to obtain the location array hash memblock addr. hash memblock addr is a numerical type. addr is the address generated by malloc, which is a random value within a range. After hashing the thread ID, the thread level needs to process less data, so the modulus 10 can be used here to perform small-range hashing.

[0063] In step S340, a linked list is constructed according to memory blocks of the same size, and the position array is used as the head node of the linked list to form a memory data structure.

[0064] Specifically, memory blocks of the same size are used to construct a linked list. At the same time, the position array corresponding to the memory block is used as the head node of the linked list. The memory data structure is obtained according to the linked list composed of all memory blocks, and the creation of the memory data structure is realized to facilitate subsequent dynamic memory allocation.

[0065] In this embodiment, the thread IDs of all threads are obtained, and the thread IDs are hashed to obtain an ID array. The unique identification of the thread is hashed to facilitate fast search and management of the thread. The memory block size corresponding to the thread is obtained according to the thread ID in the ID array, and a memory block size array is constructed. Based on the memory block size data, the position information of the memory blocks of the same size is hashed to obtain a position array. A linked list is constructed according to the memory blocks of the same size, and the unknown array is used as the head node of the linked list to form a memory data structure. The creation of the memory data structure is achieved through two hash operations, ensuring the efficient implementation of dynamic memory detection at runtime.

[0066] In one embodiment, after step S340, the method further includes: performing a locking operation on the memory data structure.

[0067] Specifically, after the memory data structure is created, the memory data structure can also be locked to implement locked protection of the memory data structure, so that multiple threads can modify the data in the same memory block at the same time, or threads need to access complex data structures to ensure the integrity and consistency of the data structure. It can also protect the critical section to prevent interruption by other threads during the execution of the critical section, thereby ensuring the execution order and results of the critical section code are correct, thereby realizing the reuse of memory allocation functions and release functions.

[0068] Figure 7 is a flowchart of a method for calling a dynamic link library through a dynamic memory release interface according to an exemplary embodiment. Figure 7 As shown, the method of calling the dynamic link library through the dynamic memory release interface is used in step S120, including the following steps:

[0069] In step S410, a memory release function is called through a dynamic memory release interface to obtain a thread ID and a memory address of a thread to be released.

[0070] Specifically, Figure 4 As shown, after the thread in the application to be detected finishes running, the memory occupied by the thread needs to be released for the next use. When releasing the memory, the memory release function in the dynamic link library is called through the dynamic memory release interface to obtain the thread ID and memory address of the thread to be released, so as to facilitate accurate memory release.

[0071] In step S420, based on the thread ID and the memory address, it is searched whether the memory data structure corresponding to the thread to be released exists.

[0072] Specifically, since the memory data structure is created by hashing the thread ID and location information twice, when releasing the memory, the thread ID and memory address of the thread to be released are first obtained, so that by performing two hash operations on the thread ID and the memory address, it is possible to find out whether the corresponding memory data structure exists, so as to perform corresponding processing according to the judgment result.

[0073] In step S430, if the corresponding memory data structure does not exist, the kernel generates an interrupt signal, completes memory release exception detection, and outputs the positioning result according to the thread ID and the memory address.

[0074] Specifically, when it is determined that the corresponding memory data structure does not exist, ASSERT false indicates that the memory data structure has been released or the corresponding memory data structure does not exist. The kernel generates an interrupt signal SIGABORT, thereby completing the memory release exception detection and outputting the location result of the exception code according to the thread ID and memory address, so as to facilitate timely code adjustment.

[0075] During normal debugging of the program, this step has diagnosed and located the abnormal code, so the program crashes and generates a core dump file. If you need to distinguish between memory leaks and multiple releases, you need to perform corresponding follow-up processing.

[0076] In step S440, if a corresponding memory data structure exists, the memory is released according to the memory address, and it is determined whether the memory data structure is empty. If the memory data structure is empty, the resources of the initial memory data structure in the dynamic link library are cleaned up; if the memory data structure is not empty, the memory data structure is released.

[0077] Specifically, when it is determined that there is a corresponding memory data structure, it means that the memory of the thread to be released has not been released, and the free function is used to release the memory according to the memory address; at the same time, it is determined whether the memory data structure is empty, that is, whether the thread stops occupying the memory. Among them, when the memory data structure is empty, the resources of the initial memory data structure created in the dynamic link library are cleaned up; when the memory data structure is not empty, the memory data structure of the corresponding thread is released, and the free function ends, realizing the memory release of the thread to be released, so as to facilitate subsequent memory allocation.

[0078] In this embodiment, when dynamic memory release is performed, a dynamic memory release interface is used to call a memory release function, and the thread ID and memory address of the thread to be released are obtained. According to the thread ID and the memory address, it is found whether the memory data structure corresponding to the thread to be released exists. When the corresponding memory data structure does not exist, the program crashes, the kernel generates an interrupt signal, and a core dump is performed, which is convenient for development debugging and locating the exception. The memory release exception detection is completed, and the location result of the exception code is output according to the thread ID and the memory address, so that the developer can handle it in time; when the corresponding memory data structure exists, the memory is released according to the memory address, and it is determined whether the memory data structure is empty. When the memory data structure is empty, the resources of the initial memory data structure in the dynamic link library are cleared. When the memory data structure is not empty, the memory data structure is released. The memory release exception detection and code location can be completed while the memory release is realized, so that the memory release exception problem can be discovered and solved in a timely and effective manner, ensuring the stable operation of the program.

[0079] Figure 8 is a flowchart of a method for outputting positioning results according to an exemplary embodiment. Figure 8 As shown, the method for outputting the positioning result is used in step S120, comprising the following steps:

[0080] In step S510, a core dump file is generated according to the thread ID and the memory address, and a call stack is formed through GDB parsing.

[0081] Specifically, when locating the abnormal code, a core dump file is generated according to the corresponding thread ID and memory address, and parsed by GDB to view the running status of the program and form a call stack so as to locate the abnormal code according to the call stack.

[0082] In step S520, the exception code corresponding to the thread to be released is located according to the call stack.

[0083] Specifically, through the call stack obtained by the GDB debugging tool, obtain the complete exception call stack information, check the information in the call stack, find the exact location where the exception occurred, and locate the exception code corresponding to the thread to be released; check the exception code to determine the possible cause of the exception, and finally modify the code to solve the problem, retest to ensure that the problem has been solved, thereby locating and solving the exception code corresponding to the thread to be released.

[0084] In this embodiment, when an abnormal memory release is detected, a core dump file is generated according to the thread ID and the memory address, a call stack is formed through GDB analysis, and the exception code corresponding to the thread to be released is located according to the call stack, thereby achieving rapid positioning of the exception code, so that timely processing can be performed according to the exception code, and it can be applied to memory exception positioning in various scenarios.

[0085] Exemplary Devices

[0086] Fig. 9 The following is a block diagram of a device for diagnosing and locating a dynamic memory release anomaly according to an exemplary embodiment. Fig. 9 The device 900 includes a dynamic link library customization module 910 and a positioning result output module 920.

[0087] The dynamic link library customization module 910 is used to customize the dynamic link library and make the environment variable of the application to be detected point to the path of the dynamic link library, and the dynamic link library includes a memory allocation function and a memory release function;

[0088] The positioning result output module 920 is used to run the application to be detected, call the dynamic link library through the dynamic memory interface, locate the code of the dynamic memory release exception, and output the positioning result.

[0089] In some embodiments, the device also includes: a resource usage detection module, which is used to call the memory allocation function through the dynamic memory application interface to detect whether the resource usage is empty; a resource initialization module, which is used to initialize resources through built-in global static variables when the resource usage is empty, and create a memory data structure to perform dynamic memory allocation; a memory information writing module, which is used to obtain the current thread ID, memory address and memory allocation size when the resource usage is not empty, and write it into the memory data structure to perform dynamic memory allocation.

[0090] In some embodiments, the device also includes: a thread ID hash module, which is used to obtain the thread IDs of all threads and perform hash operations on the thread IDs to obtain an ID array; a memory block size data construction module, which is used to obtain the memory block size corresponding to the thread according to the thread ID in the ID array and construct a memory block size array; a memory block hash module, which is used to hash the position information of memory blocks of the same size based on the memory block size array to obtain a position array; a memory data structure construction module, which is used to construct a linked list based on memory blocks of the same size, and use the position array as the head node of the linked list to form a memory data structure.

[0091] In some embodiments, the device also includes: a memory release function calling module, which is used to call the memory release function through the dynamic memory release interface to obtain the thread ID and memory address of the thread to be released; a memory data structure search module, which is used to search for the existence of the memory data structure corresponding to the thread to be released according to the thread ID and the memory address; an exception detection module, which is used to generate an interrupt signal in the kernel when the corresponding memory data structure does not exist, complete the memory release exception detection, and output the positioning result according to the thread ID and the memory address; a memory data structure judgment module, which is used to release the memory according to the memory address when the corresponding memory data structure exists, and judge whether the memory data structure is empty; wherein, if the memory data structure is empty, the resources of the initial memory data structure in the dynamic link library are cleaned up; if the memory data structure is not empty, the memory data structure is released.

[0092] In some embodiments, the device also includes: a call stack formation module, which is used to generate a core dump file according to the thread ID and the memory address, and form a call stack through GDB parsing; an exception code positioning module, which is used to locate the exception code corresponding to the thread to be released according to the call stack.

[0093] In some embodiments, the device further includes: a locking module, configured to perform locking operations on the memory data structure.

[0094] In the above embodiment, through the operation of the device, a method for diagnosing and locating a dynamic memory release anomaly is implemented, ensuring that the device can implement all contents of a method for diagnosing and locating a dynamic memory release anomaly.

[0095] Exemplary Electronic Devices

[0096] Fig.10 1 is a block diagram of an electronic device 1000 according to an exemplary embodiment. The electronic device 1000 may be a vehicle controller, a vehicle terminal, a vehicle computer or other types of electronic devices.

[0097] Reference Fig.10 , the electronic device 1000 may include at least one processor 1010 and a memory 1020. The processor 1010 may execute instructions stored in the memory 1020. The processor 1010 is communicatively connected to the memory 1020 via a data bus. In addition to the memory 1020, the processor 1010 may also be communicatively connected to an input device 1030, an output device 1040, and a communication device 1050 via a data bus.

[0098] The processor 1010 may be any conventional processor, such as a commercially available CPU. The processor may also include a graphics processor (Graphic Process Unit, GPU), a field programmable gate array (Field Programmable Gate Array, FPGA), a system on chip (System on Chip, SOC), an application specific integrated circuit (Application Specific Integrated Circuit, ASIC) or a combination thereof.

[0099] Memory 1020 can be implemented by any type of volatile or non-volatile storage device or a combination thereof, such as static random access memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic memory, flash memory, magnetic disk or optical disk.

[0100] In an embodiment of the present disclosure, executable instructions are stored in the memory 1020, and the processor 1010 can read the executable instructions from the memory 1020 and execute the instructions to implement all or part of the steps of a method for diagnosing and locating a dynamic memory release anomaly described in any of the above exemplary embodiments.

[0101] Exemplary computer-readable storage media

[0102] In addition to the above methods and devices, the exemplary embodiments of the present disclosure may also be a computer program product or a computer-readable storage medium storing the computer program product. The computer product includes computer program instructions that can be executed by a processor to implement all or part of the steps described in any method in the above exemplary embodiments.

[0103] The computer program product may be written in any combination of one or more programming languages ​​to write program codes for performing the operations of the embodiments of the present application, including object-oriented programming languages, such as Java, C++, etc., and also conventional procedural programming languages, such as "C" language or similar programming languages ​​and scripting languages ​​(e.g., Python). The program code may be executed entirely on the user computing device, partially on the user computing device, as an independent software package, partially on the user computing device and partially on the remote computing device, or entirely on the remote computing device or server.

[0104] The computer readable storage medium can adopt any combination of one or more readable media. The readable medium can be a readable signal medium or a readable storage medium. The readable storage medium can include, for example, but is not limited to, a system, device or device of electricity, magnetism, light, electromagnetic, infrared, or semiconductor, or any combination of the above. More specific examples of readable storage media include: a static random access memory (SRAM) with one or more wires electrically connected, an electrically erasable programmable read-only memory (EEPROM), an erasable programmable read-only memory (EPROM), a programmable read-only memory (PROM), a read-only memory (ROM), a magnetic storage, a flash memory, a magnetic disk or an optical disk, or any suitable combination of the above.

[0105] Those skilled in the art will readily appreciate other embodiments of the present disclosure after considering the specification and practicing the present disclosure. This application is intended to cover any variations, uses or adaptations of the present disclosure, which follow the general principles of the present disclosure and include common knowledge or customary technical means in the art that are not disclosed in the present disclosure. The specification and examples are to be considered as exemplary only, and the true scope and spirit of the present disclosure are indicated by the following claims.

[0106] It should be understood that the present disclosure is not limited to the exact structures that have been described above and shown in the drawings, and that various modifications and changes may be made without departing from the scope thereof. The scope of the present disclosure is limited only by the appended claims.

Claims

1. A method for diagnosing and locating abnormal dynamic memory release, characterized in that: include: Customizing a dynamic link library and making the environment variable of the application to be detected point to the path of the dynamic link library, wherein the dynamic link library includes a memory allocation function and a memory release function; The application program to be detected is run, the dynamic link library is called through a dynamic memory interface, the code of the abnormal dynamic memory release is located, and the location result is output.

2. The method for diagnosing and locating abnormal dynamic memory release according to claim 1, characterized in that: The dynamic memory interface includes a dynamic memory application interface and a dynamic memory release interface. When dynamically allocating memory, the thread ID, memory address and memory allocation size are recorded through a memory data structure. When dynamically releasing memory, an error signal is generated by triggering the presence of a corresponding memory data structure to implement the code for locating the dynamic memory release exception.

3. The method for diagnosing and locating abnormal dynamic memory release according to claim 2, characterized in that: When the dynamic link library is called through the dynamic memory application interface, it includes: Call the memory allocation function through the dynamic memory application interface to detect whether the resource usage is empty; If the resource usage is empty, the resource is initialized through the built-in global static variables, and a memory data structure is created to perform dynamic memory allocation; If the resource usage is not empty, the current thread ID, memory address and memory allocation size are obtained and written into the memory data structure to perform dynamic memory allocation.

4. The method for diagnosing and locating abnormal dynamic memory release according to claim 3, characterized in that: The creating of the memory data structure comprises: Obtain thread IDs of all threads, and perform hash operations on the thread IDs to obtain an ID array; Obtain the memory block size corresponding to the thread according to the thread ID in the ID array, and construct a memory block size array; Based on the memory block size array, hash processing is performed on the position information of the memory blocks of the same size to obtain a position array; A linked list is constructed according to memory blocks of the same size, and the position array is used as a head node of the linked list to form a memory data structure.

5. The method for diagnosing and locating abnormal dynamic memory release according to claim 2, characterized in that: When the dynamic link library is called through the dynamic memory release interface, it includes: Call the memory release function through the dynamic memory release interface to obtain the thread ID and memory address of the thread to be released; According to the thread ID and the memory address, searching whether the memory data structure corresponding to the thread to be released exists; If there is no corresponding memory data structure, the kernel generates an interrupt signal, completes memory release exception detection, and outputs a positioning result according to the thread ID and memory address; If a corresponding memory data structure exists, releasing the memory according to the memory address, and determining whether the memory data structure is empty; If the memory data structure is empty, the resources of the initial memory data structure in the dynamic link library are cleared; if the memory data structure is not empty, the memory data structure is released.

6. The method for diagnosing and locating abnormal dynamic memory release according to claim 5, characterized in that: Outputting the positioning result according to the thread ID and the memory address includes: Generate a core dump file according to the thread ID and memory address, and parse it through GDB to form a call stack; According to the call stack, the exception code corresponding to the thread to be released is located.

7. The method for diagnosing and locating abnormal dynamic memory release according to claim 3, characterized in that: After the memory data structure is created, the following steps are also included: A locking operation is performed on the memory data structure.

8. A diagnostic and positioning device for abnormal dynamic memory release, characterized in that: include: A dynamic link library customization module, used for customizing the dynamic link library and making the environment variable of the application to be detected point to the path of the dynamic link library, wherein the dynamic link library includes a memory allocation function and a memory release function; The positioning result output module is used to run the application to be detected, call the dynamic link library through the dynamic memory interface, locate the code of the dynamic memory release exception, and output the positioning result.

9. An electronic device, characterized in that: include: processor; a memory for storing instructions executable by the processor; The processor is used to read the executable instructions from the memory and execute the instructions to implement the diagnosis and positioning method of dynamic memory release anomaly described in any one of claims 1-7.

10. A computer-readable storage medium having computer program instructions stored thereon, characterized in that: When the program instructions are executed by a processor, the steps of the method for diagnosing and locating a dynamic memory release anomaly described in any one of claims 1 to 7 are implemented.