CN116382910A - Resource release detection method and device - Google Patents

Resource release detection method and device Download PDF

Info

Publication number
CN116382910A
CN116382910A CN202310350932.8A CN202310350932A CN116382910A CN 116382910 A CN116382910 A CN 116382910A CN 202310350932 A CN202310350932 A CN 202310350932A CN 116382910 A CN116382910 A CN 116382910A
Authority
CN
China
Prior art keywords
resource
resource operation
determining
release
detection result
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202310350932.8A
Other languages
Chinese (zh)
Inventor
周小亮
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Ping An Technology Shenzhen Co Ltd
Original Assignee
Ping An Technology Shenzhen Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Ping An Technology Shenzhen Co Ltd filed Critical Ping An Technology Shenzhen Co Ltd
Priority to CN202310350932.8A priority Critical patent/CN116382910A/en
Publication of CN116382910A publication Critical patent/CN116382910A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/50Allocation of resources, e.g. of the central processing unit [CPU]
    • G06F9/5005Allocation of resources, e.g. of the central processing unit [CPU] to service a request
    • G06F9/5011Allocation of resources, e.g. of the central processing unit [CPU] to service a request the resources being hardware resources other than CPUs, Servers and Terminals
    • G06F9/5022Mechanisms to release resources
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/10File systems; File servers
    • G06F16/14Details of searching files based on file metadata
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/50Allocation of resources, e.g. of the central processing unit [CPU]
    • G06F9/5005Allocation of resources, e.g. of the central processing unit [CPU] to service a request
    • G06F9/5011Allocation of resources, e.g. of the central processing unit [CPU] to service a request the resources being hardware resources other than CPUs, Servers and Terminals
    • G06F9/5016Allocation of resources, e.g. of the central processing unit [CPU] to service a request the resources being hardware resources other than CPUs, Servers and Terminals the resource being the memory
    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
    • Y02D10/00Energy efficient computing, e.g. low power processors, power management or thermal management

Abstract

The application relates to the technical field of data processing, and provides a method and a device for detecting release of resources. The method comprises the following steps: performing resource operation matching on the abstract syntax tree of any target file in each development file according to preset resource operation, and obtaining a resource matching result; determining that a resource matching result is that a resource operation object corresponding to a preset resource operation exists, instantiating the resource operation object, and acquiring variable information pointed after the resource operation object is instantiated; and matching the variable information with each node of the abstract syntax tree, and determining a first resource release detection result of the target file. The method for detecting the release of the resources can improve the accuracy of detecting the release result of the resources.

Description

Resource release detection method and device
Technical Field
The present invention relates to the field of data processing technologies, and in particular, to a method and an apparatus for detecting resource release.
Background
In the process of software development, the operation of resources on files, IO streams and databases is a problem frequently encountered in development. Because resources such as files, IO streams, database connection and the like cannot be automatically released, in the process of operating each resource, the release of the resource is detected, so that the problem that the memory is exhausted and programs and systems crash due to the fact that the resources cannot be released is avoided. In the related art, the release detection of the resource is performed through the instance test, however, the reason why the resource cannot be released is usually that the code of the code block is wrong in the logic structure of the exception capture, and the wrong code does not cause compiling errors, and it is difficult to find out the problem through the test, and a large amount of data pressure test is required to trigger the generation of the exception, so that whether the release result of the resource is normal cannot be effectively detected through the instance test.
Disclosure of Invention
The present application aims to solve at least one of the technical problems existing in the related art. Therefore, the application provides a method for detecting the release of resources, which can improve the accuracy of detecting the release result of the resources.
The application also provides a device for detecting the release of the resources.
The application also provides electronic equipment.
The present application also proposes a computer-readable storage medium.
The method for detecting the release of the resources according to the embodiment of the first aspect of the application comprises the following steps:
performing resource operation matching on the abstract syntax tree of any target file in each development file according to preset resource operation, and obtaining a resource matching result;
determining that the resource matching result is that a resource operation object corresponding to the preset resource operation exists, instantiating the resource operation object, and acquiring variable information pointed by the resource operation object after being instantiated;
and matching the variable information with each node of the abstract syntax tree, and determining a first resource release detection result of the target file.
According to the resource release detection method provided by the embodiment of the invention, the abstract syntax tree of any target file in each development file is subjected to resource operation matching according to the preset resource operation, after the resource operation object corresponding to the preset resource operation is obtained, the resource operation object is instantiated, the variable information pointed by the resource operation object after the instantiation is obtained, so that the first resource release detection result of the target file is determined according to the variable information matched with each node of the abstract syntax tree, and therefore, whether the unreleased code of the resource exists in the target file is rapidly checked in a mode of matching the variable information pointed by the resource operation object after the instantiation with each node of the abstract syntax tree of the target file, and further, the detection result of resource release can be accurately determined only by matching the bottom code file, the detection efficiency of resource release is improved, and the accuracy of resource release result detection is improved.
According to one embodiment of the present application, further comprising:
and acquiring the target file with the file name suffix identical to the preset file suffix from each development file according to the preset file suffix.
According to one embodiment of the present application, the matching the variable information with each node of the abstract syntax tree, and determining the first resource release detection result of the target file includes:
and determining that a target node matched with the variable information exists in each node, and determining the first resource release detection result as no risk of resource unreleasability exists.
According to one embodiment of the present application, further comprising:
determining that a circulation statement exists in the target file, and searching resource operation information corresponding to the preset resource operation from the circulation statement;
and determining that the resource operation information exists in the circulating statement, detecting the final code block of the circulating statement, and obtaining a second resource release detection result.
According to an embodiment of the present application, detecting the find code block of the loop sentence, to obtain a second resource release detection result, includes:
and determining that the code block detection result is that the finaly code block exists in the cyclic statement, wherein the finaly code block comprises a closing statement of the resource operation object, and determining that the second resource release detection result does not have the risk of unreleasable resource.
According to one embodiment of the present application, further comprising:
and determining a final resource release detection result of the target file according to the first resource release detection result and the second resource release detection result.
According to one embodiment of the present application, further comprising:
and determining that the resource matching result is that a resource operation object corresponding to the preset resource operation does not exist, and skipping the target file.
According to an embodiment of the second aspect of the present application, a device for detecting release of resources includes:
the resource operation matching module is used for carrying out resource operation matching on the abstract syntax tree of any target file in each development file according to preset resource operation to obtain a resource matching result;
the variable information acquisition module is used for determining that the resource matching result is that a resource operation object corresponding to the preset resource operation exists, instantiating the resource operation object and acquiring the variable information pointed by the resource operation object after the resource operation object is instantiated;
and the resource release detection module is used for matching the variable information with each node of the abstract syntax tree and determining a first resource release detection result of the target file.
An electronic device according to an embodiment of a third aspect of the present application includes a processor and a memory storing a computer program, where the processor implements the method for detecting release of resources according to any of the above embodiments when executing the computer program.
A computer readable storage medium according to an embodiment of a fourth aspect of the present application, on which a computer program is stored, which when executed by a processor, implements the method for detecting release of resources according to any of the above embodiments.
A computer program product according to an embodiment of the fifth aspect of the present application, comprising: the computer program, when executed by a processor, implements the method for detecting release of resources according to any of the embodiments described above.
The above technical solutions in the embodiments of the present application have at least one of the following technical effects:
according to the method, resource operation matching is conducted on an abstract syntax tree of any target file in each development file according to preset resource operation, after a resource operation object corresponding to the preset resource operation is obtained, the resource operation object is instantiated, variable information pointed after the resource operation object is instantiated is obtained, matching is conducted on each node of the abstract syntax tree according to the variable information, and a first resource release detection result of the target file is determined, so that whether a resource unreleased code exists in the target file or not is rapidly checked in a mode that the variable information pointed after the resource operation object is instantiated is matched with each node of the abstract syntax tree of the target file, a large amount of data pressure tests are not needed, the detection result of resource release can be accurately determined only through matching of a bottom code file, the detection efficiency of resource release is improved, and the accuracy of resource release result detection is improved.
Further, after all the development files of the project are obtained, according to the preset file suffixes, all the development files with file names and suffixes being preset file suffixes are searched from all the development files to serve as target files, so that the situation that the obtained target files are files which are not used for recording resource operation objects and the follow-up detection efficiency and detection accuracy are affected is avoided.
Further, by detecting the circulation statement of the target file, searching the resource operation information corresponding to the preset resource operation from the circulation statement after determining that the circulation statement exists in the target file, detecting the finish code block of the circulation statement when determining that the resource operation information exists in the circulation statement, and obtaining a second resource release detection result, the obtained resource release detection result contains the influence caused by the circulation statement, and accuracy of the obtained resource release detection result is further improved.
Further, after the first resource release detection result and the second resource release detection result are obtained, a final resource release detection result is determined according to the first resource release detection result and the second resource release detection result, so that the finally obtained resource release detection result is more accurate.
Drawings
For a clearer description of the present application or of the prior art, the drawings that are used in the description of the embodiments or of the prior art will be briefly described, it being apparent that the drawings in the description below are some embodiments of the present application, and that other drawings may be obtained from these drawings without inventive effort for a person skilled in the art.
Fig. 1 is a flow chart of a method for detecting release of resources according to an embodiment of the present application;
fig. 2 is a flow chart of a method for detecting release of resources according to another embodiment of the present application;
fig. 3 is a schematic structural diagram of a device for detecting release of resources according to an embodiment of the present application;
fig. 4 is a schematic structural diagram of an electronic device according to an embodiment of the present application.
Detailed Description
For the purposes of making the objects, technical solutions and advantages of the present application more apparent, the technical solutions in the present application will be clearly and completely described below with reference to the accompanying drawings in the embodiments of the present application, and it is apparent that the described embodiments are some, but not all, embodiments of the present application. All other embodiments, which can be made by one of ordinary skill in the art based on the embodiments herein without making any inventive effort, are intended to be within the scope of the present application.
The method and apparatus for detecting the release of resources provided in the embodiments of the present application will be described and illustrated in detail below by means of several specific embodiments.
In an embodiment, a method for detecting release of resources is provided, and the method is applied to a server and is used for detecting whether the resources have risk of being unable to release. The server may be an independent server or a server cluster formed by a plurality of servers, and may also be a cloud server for providing cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communication, middleware services, domain name services, security services, CDNs, basic cloud computing services such as big data and artificial intelligent sampling point devices, and the like.
As shown in fig. 1, the method for detecting release of resources provided in this embodiment includes:
step 101, performing resource operation matching on an abstract syntax tree of any target file in each development file according to preset resource operation, and obtaining a resource matching result;
102, determining that the resource matching result is that a resource operation object corresponding to the preset resource operation exists, instantiating the resource operation object, and obtaining variable information pointed by the resource operation object after being instantiated;
and step 103, matching the variable information with each node of the abstract syntax tree, and determining a first resource release detection result of the target file.
According to the method, resource operation matching is conducted on an abstract syntax tree of any target file in each development file according to preset resource operation, after a resource operation object corresponding to the preset resource operation is obtained, the resource operation object is instantiated, variable information pointed after the resource operation object is instantiated is obtained, matching is conducted on each node of the abstract syntax tree according to the variable information, and a first resource release detection result of the target file is determined, so that whether a resource unreleased code exists in the target file or not is rapidly checked in a mode that the variable information pointed after the resource operation object is instantiated is matched with each node of the abstract syntax tree of the target file, a large amount of data pressure tests are not needed, the detection result of resource release can be accurately determined only through matching of a bottom code file, the detection efficiency of resource release is improved, and the accuracy of resource release result detection is improved.
In an embodiment, the resource operation object may be any one of a file, an IO stream, or a database. The preset resource operation refers to a preset operation on a resource operation object, such as a database checking operation. When the resource operation is matched with the abstract syntax tree of any target file in each development file according to the preset resource operation, in order to avoid missing the matching of the resource operation object of the abstract syntax tree, the preset resource operation can be the resource operation of any resource operation object.
In an embodiment, the acquiring of each development file may be that the server acquires all development files of the project from a project management warehouse gitlab through a gitclone command, and then selects a part of files from all development files as target files. While the relevant code that allows for resource release is typically stored in a fixed suffix development file, such as in a file with a file name suffix ". Java". Therefore, to improve the detection efficiency and the accuracy of the final detection result, the method further includes: and acquiring the target file with the file name suffix identical to the preset file suffix from each development file according to the preset file suffix.
In an embodiment, after all development files of a project are obtained, according to a preset file suffix ". Java", all development files with file names suffix ". Java" are searched from all development files to serve as target files, and the target files are added into a file list to be analyzed, so that the obtained target files are files which are not used for recording resource operation objects, and the subsequent detection efficiency and detection accuracy are prevented from being affected.
In an embodiment, after the file list to be analyzed is obtained, each target file in the file list to be analyzed is sequentially and circularly listed, and for any target file in the file list to be analyzed, a java abstract syntax tree is constructed for the target file, and at the moment, the constructed abstract syntax tree can search related nodes through xpath. After the construction of the java abstract syntax tree of the target file is completed, the java abstract syntax tree of each target file can be matched with the preset resource operation in sequence according to the listing result of each target file. The java abstract syntax tree of any target file can be globally searched through Xpath matching according to preset resource operation, so that whether related nodes for carrying out preset resource operation on resource operation objects such as files, IO streams and databases exist in the java abstract syntax tree or not is searched, and a resource matching result is determined according to the search result. If the related node is found to exist, determining that a resource matching result is that a resource operation object exists in the abstract syntax tree; otherwise, determining that the resource matching result is that no resource operation object exists in the abstract syntax tree.
In an embodiment, after a resource matching result is obtained, if the resource matching result is that a resource operation object corresponding to a preset resource operation does not exist in the abstract syntax tree, it is indicated that the java source code of the target file does not exist the resource operation, at this time, the current target file may be skipped, and after a next target file is obtained from the file list to be analyzed, the abstract syntax tree of the next target file is matched with the preset resource operation.
In an embodiment, if the resource matching result is that a resource operation object corresponding to a preset resource operation exists in the abstract syntax tree, it is indicated that the resource operation exists in the java source code of the target file, at this time, the resource operation object is extracted from the abstract syntax tree, then the extracted resource operation object is instantiated, and variable information pointed after the resource object instantiation is extracted from the code of the target file. After the variable information is obtained, the variable information can be matched with each node of the abstract syntax tree to find out whether the node which is the same as the variable information exists in the abstract syntax tree.
And considering that a for loop statement may exist in java source code of the target file, the for loop may affect the consumption of the resource, thereby affecting the release of the resource. Therefore, in order to further improve the accuracy of the release detection of the resources, in an embodiment, after the variable information is acquired, the whole abstract syntax tree may be matched through a blockstate/fortatavent expression, if the matching result is null, it indicates that there is no for loop in the java source code in the target file, at this time, only the variable information needs to be matched with each node of the abstract syntax tree, and it can be directly determined whether there is a resource operation closing statement in the java source code, thereby determining a first resource release detection result, and taking the first resource release detection result as a final resource release detection result of the target file.
Specifically, when it is determined that no cyclic statement exists in the target file, the variable information is matched with each node of the abstract syntax tree, if the matching result of the variable information and each node is that a target node matched with the variable information exists in each node, that is, the matching result output is not O, the java source code of the target file has a resource operation object closing statement, the resource is released, and at this time, the first resource release detection result is determined to be free of the risk that the resource cannot be released. If the matching result of the variable information and each node is that the target node matched with the variable information does not exist in each node, namely the matching result output is O, a resource operation object closing statement does not exist in the java source code of the target file, the resource is not released, and at the moment, the first resource release detection result is determined to be at risk of unreleasable resource. In this way, whether the risk of unreleased resources exists can be determined by judging whether the target node matched with the variable information exists.
In order to make the obtained first resource release detection result more accurate, in an embodiment, after determining that a target node matching the variable information exists in each node, the target node may also be matched with the finaly code block, considering that the resource release is usually performed in the finaly code block. If the target node is the same as the finaly code block, the target node indicates that a resource operation object closing statement exists in the finaly code block, and at this time, the first resource release detection result can be determined as that the risk that the resource cannot be released does not exist. If the target node is different from the finaly code block, the fact that the resource operation object closing statement does not exist in the finaly code block is indicated, and at the moment, the first resource release detection result can be determined to be at risk of resource unreleasing.
When it is determined that the java source code of the target file has a for loop statement, in order to accurately acquire the first resource release detection result, in an embodiment, as shown in fig. 2, the method further includes:
step 201, determining that a circulation sentence exists in the target file, matching the variable information with each node of the abstract syntax tree, determining the first resource release detection result, and searching resource operation information corresponding to the preset resource operation from the circulation sentence;
step 202, determining that the resource operation information exists in the circulation statement, and detecting the complete code block of the circulation statement to obtain a second resource release detection result.
In an embodiment, when the whole abstract syntax tree is matched through the blockstate/fortatavent expression, if the matching result is not null, it indicates that a java source code in the target file has a for loop sentence, at this time, variable information is matched with each node of the abstract syntax tree, after determining a first resource release detection result, whether a preset resource operation for a resource operation object such as a file, an IO stream or a database exists is searched according to the for loop sentence. If not, skipping analysis of the for loop sentence; if so, determining that the resource operation information exists in the loop sentence, and detecting whether the finall code block exists in the for loop sentence. If the finaly code block does not exist, the fact that the resource operation object closing statement is absent in the for loop statement is indicated, and at the moment, the second resource release detection result is determined to be the risk that resources cannot be released. If the finaliy code block exists, whether a resource operation object closing statement exists in the finaliy code block is further detected. If the final code block does not have a closing statement of the resource operation object, determining a second resource release detection result as a risk that the resource cannot be released; and if the resource operation object closing statement exists in the final code block, determining that the risk that the resource cannot be released does not exist as a second resource release detection result.
The target file is detected through a circulation statement, after the circulation statement exists in the target file, resource operation information corresponding to preset resource operation is searched from the circulation statement, when the resource operation information exists in the circulation statement, the circulation statement is detected through a final code block, and a second resource release detection result is obtained, so that the obtained resource release detection result contains the influence caused by the circulation statement, and the accuracy of the obtained resource release detection result is further improved.
In an embodiment, after the second resource release detection result is obtained, detecting the first resource release detection result and the second resource release detection result; if at least one of the first resource release detection result or the second resource release detection result is a risk that resources cannot be released, determining that a final resource release detection result of the target file is a risk that resources cannot be released; if the first resource release detection result and the second resource release detection result are both free of the risk that resources cannot be released, the final resource release detection result is identical to the first resource release detection result and the second resource release detection result.
After the first resource release detection result and the second resource release detection result are obtained, the final resource release detection result is determined according to the first resource release detection result and the second resource release detection result, so that the finally obtained resource release detection result is more accurate.
The release detection device of the resource provided by the application is described below, and the release detection device of the resource described below and the release detection method of the resource described above can be referred to correspondingly to each other.
In one embodiment, as shown in fig. 3, there is provided a device for detecting release of resources, including:
the resource operation matching module 210 is configured to perform resource operation matching on the abstract syntax tree of any target file in each development file according to a preset resource operation, so as to obtain a resource matching result;
the variable information obtaining module 220 is configured to determine that the resource matching result is that there is a resource operation object corresponding to the preset resource operation, instantiate the resource operation object, and obtain variable information pointed by the resource operation object after being instantiated;
the resource release detection module 230 is configured to match the variable information with each node of the abstract syntax tree, and determine a first resource release detection result of the target file.
According to the method, resource operation matching is conducted on an abstract syntax tree of any target file in each development file according to preset resource operation, after a resource operation object corresponding to the preset resource operation is obtained, the resource operation object is instantiated, variable information pointed after the resource operation object is instantiated is obtained, matching is conducted on each node of the abstract syntax tree according to the variable information, and a first resource release detection result of the target file is determined, so that whether a resource unreleased code exists in the target file or not is rapidly checked in a mode that the variable information pointed after the resource operation object is instantiated is matched with each node of the abstract syntax tree of the target file, a large amount of data pressure tests are not needed, the detection result of resource release can be accurately determined only through matching of a bottom code file, the detection efficiency of resource release is improved, and the accuracy of resource release result detection is improved.
In one embodiment, the resource operation matching module 210 is further configured to:
and acquiring the target file with the file name suffix identical to the preset file suffix from each development file according to the preset file suffix.
In one embodiment, the resource release detection module 230 is specifically configured to:
and determining that a target node matched with the variable information exists in each node, and determining the first resource release detection result as no risk of resource unreleasability exists.
In an embodiment, the resource release detection module 230 is further configured to:
determining that a circulation statement exists in the target file, and searching resource operation information corresponding to the preset resource operation from the circulation statement;
and determining that the resource operation information exists in the circulating statement, detecting the final code block of the circulating statement, and obtaining a second resource release detection result.
In one embodiment, the resource release detection module 230 is specifically configured to:
and determining that the code block detection result is that the finaly code block exists in the cyclic statement, wherein the finaly code block comprises a closing statement of the resource operation object, and determining that the second resource release detection result does not have the risk of unreleasable resource.
In an embodiment, the resource release detection module 230 is further configured to:
and determining a final resource release detection result of the target file according to the first resource release detection result and the second resource release detection result.
In an embodiment, the variable information obtaining module 220 is further configured to:
and determining that the resource matching result is that a resource operation object corresponding to the preset resource operation does not exist, and skipping the target file.
Fig. 4 illustrates a physical schematic diagram of an electronic device, as shown in fig. 4, which may include: processor 810, communication interface (Communication Interface) 820, memory 830, and communication bus 840, wherein processor 810, communication interface 820, memory 830 accomplish communication with each other through communication bus 840. The processor 810 may call a computer program in the memory 830 to perform a method of detecting release of resources, including, for example:
performing resource operation matching on the abstract syntax tree of any target file in each development file according to preset resource operation, and obtaining a resource matching result;
determining that the resource matching result is that a resource operation object corresponding to the preset resource operation exists, instantiating the resource operation object, and acquiring variable information pointed by the resource operation object after being instantiated;
and matching the variable information with each node of the abstract syntax tree, and determining a first resource release detection result of the target file.
Further, the logic instructions in the memory 830 described above may be implemented in the form of software functional units and may be stored in a computer-readable storage medium when sold or used as a stand-alone product. Based on such understanding, the technical solution of the present application may be embodied essentially or in a part contributing to the prior art or in a part of the technical solution, in the form of a software product stored in a storage medium, including several instructions for causing a computer device (which may be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the methods of the embodiments of the present application. And the aforementioned storage medium includes: a U-disk, a removable hard disk, a Read-Only Memory (ROM), a random access Memory (RAM, random Access Memory), a magnetic disk, or an optical disk, or other various media capable of storing program codes.
In another aspect, embodiments of the present application further provide a storage medium, where the storage medium includes a computer program, where the computer program may be stored on a non-transitory computer readable storage medium, and when the computer program is executed by a processor, the computer is capable of executing the method for detecting release of resources provided in the foregoing embodiments, for example, including:
performing resource operation matching on the abstract syntax tree of any target file in each development file according to preset resource operation, and obtaining a resource matching result;
determining that the resource matching result is that a resource operation object corresponding to the preset resource operation exists, instantiating the resource operation object, and acquiring variable information pointed by the resource operation object after being instantiated;
and matching the variable information with each node of the abstract syntax tree, and determining a first resource release detection result of the target file.
In another aspect, embodiments of the present application further provide a processor-readable storage medium storing a computer program, where the computer program is configured to cause a processor to perform a method provided in the foregoing embodiments, for example, including:
performing resource operation matching on the abstract syntax tree of any target file in each development file according to preset resource operation, and obtaining a resource matching result;
determining that the resource matching result is that a resource operation object corresponding to the preset resource operation exists, instantiating the resource operation object, and acquiring variable information pointed by the resource operation object after being instantiated;
and matching the variable information with each node of the abstract syntax tree, and determining a first resource release detection result of the target file.
The processor-readable storage medium may be any available medium or data storage device that can be accessed by a processor including, but not limited to, magnetic memory (e.g., floppy disk, hard disk, tape, magneto-optical disk (MO), etc.), optical memory (e.g., CD, DVD, BD, HVD, etc.), and semiconductor memory (e.g., ROM, EPROM, EEPROM, nonvolatile memory (NAND FLASH), solid State Disk (SSD)), etc.
The apparatus embodiments described above are merely illustrative, wherein elements illustrated as separate elements may or may not be physically separate, and elements shown as elements may or may not be physical elements, may be located in one place, or may be distributed over a plurality of network elements. Some or all of the modules may be selected according to actual needs to achieve the purpose of the solution of this embodiment. Those of ordinary skill in the art will understand and implement the present invention without undue burden.
From the above description of the embodiments, it will be apparent to those skilled in the art that the embodiments may be implemented by means of software plus necessary general hardware platforms, or of course may be implemented by means of hardware. Based on this understanding, the foregoing technical solution may be embodied essentially or in a part contributing to the prior art in the form of a software product, which may be stored in a computer readable storage medium, such as ROM/RAM, a magnetic disk, an optical disk, etc., including several instructions for causing a computer device (which may be a personal computer, a server, or a network device, etc.) to execute the method described in the respective embodiments or some parts of the embodiments.
Finally, it should be noted that: the above embodiments are only for illustrating the technical solution of the present application, and are not limiting thereof; although the present application has been described in detail with reference to the foregoing embodiments, it should be understood by those of ordinary skill in the art that: the technical scheme described in the foregoing embodiments can be modified or some technical features thereof can be replaced by equivalents; such modifications and substitutions do not depart from the spirit and scope of the corresponding technical solutions.

Claims (10)

1. A method for detecting release of resources, comprising:
performing resource operation matching on the abstract syntax tree of any target file in each development file according to preset resource operation, and obtaining a resource matching result;
determining that the resource matching result is that a resource operation object corresponding to the preset resource operation exists, instantiating the resource operation object, and acquiring variable information pointed by the resource operation object after being instantiated;
and matching the variable information with each node of the abstract syntax tree, and determining a first resource release detection result of the target file.
2. The method for detecting the release of resources according to claim 1, further comprising:
and acquiring the target file with the file name suffix identical to the preset file suffix from each development file according to the preset file suffix.
3. The method for detecting release of resources according to claim 1, wherein matching the variable information with each node of the abstract syntax tree, determining a first resource release detection result of the target file, comprises:
and determining that a target node matched with the variable information exists in each node, and determining the first resource release detection result as no risk of resource unreleasability exists.
4. The method for detecting the release of resources according to claim 1, further comprising:
determining that a circulation statement exists in the target file, and searching resource operation information corresponding to the preset resource operation from the circulation statement;
and determining that the resource operation information exists in the circulating statement, detecting the final code block of the circulating statement, and obtaining a second resource release detection result.
5. The method for detecting release of resources according to claim 4, wherein detecting the loop statement for a complete code block to obtain a second resource release detection result includes:
and determining that the code block detection result is that the finaly code block exists in the cyclic statement, wherein the finaly code block comprises a closing statement of the resource operation object, and determining that the second resource release detection result does not have the risk of unreleasable resource.
6. The method for detecting release of resources according to claim 4 or 5, further comprising:
and determining a final resource release detection result of the target file according to the first resource release detection result and the second resource release detection result.
7. The method for detecting the release of resources according to claim 1, further comprising:
and determining that the resource matching result is that a resource operation object corresponding to the preset resource operation does not exist, and skipping the target file.
8. A release detection device for a resource, comprising:
the resource operation matching module is used for carrying out resource operation matching on the abstract syntax tree of any target file in each development file according to preset resource operation to obtain a resource matching result;
the variable information acquisition module is used for determining that the resource matching result is that a resource operation object corresponding to the preset resource operation exists, instantiating the resource operation object and acquiring the variable information pointed by the resource operation object after the resource operation object is instantiated;
and the resource release detection module is used for matching the variable information with each node of the abstract syntax tree and determining a first resource release detection result of the target file.
9. An electronic device comprising a processor and a memory storing a computer program, characterized in that the processor implements the method for detecting release of resources according to any of claims 1 to 7 when executing the computer program.
10. A computer readable storage medium having stored thereon a computer program, characterized in that the computer program, when executed by a processor, implements the method for release detection of resources according to any of claims 1 to 7.
CN202310350932.8A 2023-03-28 2023-03-28 Resource release detection method and device Pending CN116382910A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202310350932.8A CN116382910A (en) 2023-03-28 2023-03-28 Resource release detection method and device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202310350932.8A CN116382910A (en) 2023-03-28 2023-03-28 Resource release detection method and device

Publications (1)

Publication Number Publication Date
CN116382910A true CN116382910A (en) 2023-07-04

Family

ID=86961127

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202310350932.8A Pending CN116382910A (en) 2023-03-28 2023-03-28 Resource release detection method and device

Country Status (1)

Country Link
CN (1) CN116382910A (en)

Similar Documents

Publication Publication Date Title
Li et al. Where shall we log? studying and suggesting logging locations in code blocks
CN110941528B (en) Log buried point setting method, device and system based on fault
CN110941546A (en) Automatic test method, device, equipment and storage medium for WEB page case
US8904350B2 (en) Maintenance of a subroutine repository for an application under test based on subroutine usage information
CN103186463B (en) Determine the method and system of the test specification of software
CN109657475A (en) Code vulnerabilities check method, apparatus, equipment and storage medium
CN111884876A (en) Method, device, equipment and medium for detecting protocol type of network protocol
CN112363937A (en) Method and device for testing differential coverage rate, computer equipment and storage medium
US11422917B2 (en) Deriving software application dependency trees for white-box testing
CN112559343A (en) Test path generation method and related equipment
CN116431522A (en) Automatic test method and system for low-code object storage gateway
CN116382910A (en) Resource release detection method and device
CN115167896A (en) Method and device for updating software version, storage medium and electronic equipment
CN115617668A (en) Compatibility testing method, device and equipment
CN112463431B (en) BIOS error positioning method, device, equipment and storage medium
CN114490413A (en) Test data preparation method and device, storage medium and electronic equipment
CN110244954B (en) Compiling method and equipment for application program
CN111209197B (en) Application continuous integration test method, system, equipment and storage medium
CN112363936A (en) Method and device for testing differential coverage rate, computer equipment and storage medium
CN113094258A (en) Precise test method and device, computer equipment and medium
CN111160583A (en) Data processing method and device
CN113037521A (en) Method for identifying state of communication equipment, communication system and storage medium
CN112099838B (en) Method, device and storage medium for determining version difference
US20230350788A1 (en) Method and system for providing delta code coverage information for work items
CN111324523B (en) Data processing method and device

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination