CN116881129A - Method, device and computer readable medium for fast checking resource unreleased code - Google Patents

Method, device and computer readable medium for fast checking resource unreleased code Download PDF

Info

Publication number
CN116881129A
CN116881129A CN202310754180.1A CN202310754180A CN116881129A CN 116881129 A CN116881129 A CN 116881129A CN 202310754180 A CN202310754180 A CN 202310754180A CN 116881129 A CN116881129 A CN 116881129A
Authority
CN
China
Prior art keywords
resource
syntax tree
abstract syntax
searching
code
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
CN202310754180.1A
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.)
Shanghai Bilibili Technology Co Ltd
Original Assignee
Shanghai Bilibili Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Shanghai Bilibili Technology Co Ltd filed Critical Shanghai Bilibili Technology Co Ltd
Priority to CN202310754180.1A priority Critical patent/CN116881129A/en
Publication of CN116881129A publication Critical patent/CN116881129A/en
Pending legal-status Critical Current

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/36Preventing errors by testing or debugging software
    • G06F11/3604Software analysis for verifying properties of programs
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/30Creation or generation of source code
    • G06F8/31Programming languages or programming paradigms
    • G06F8/315Object-oriented languages
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/40Transformation of program code
    • G06F8/41Compilation
    • G06F8/42Syntactic analysis
    • 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

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Software Systems (AREA)
  • General Engineering & Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Computer Hardware Design (AREA)
  • Quality & Reliability (AREA)
  • Computing Systems (AREA)
  • Stored Programmes (AREA)

Abstract

The application provides a method, equipment and a computer readable medium for rapidly checking a code without releasing resources, which are characterized in that an abstract syntax tree is generated according to a code file to be checked, a resource operation object is searched in the abstract syntax tree, if the resource operation object is searched, a target variable pointed by the resource operation object after instantiation is continuously searched in the abstract syntax tree, a final module containing a resource closing statement corresponding to the target variable is searched, when the final module containing the resource closing statement corresponding to the target variable is not searched, the risk of unreleasing the resources in the code file can be confirmed, and otherwise, the risk of unreleasing the resources can be eliminated, so that automatic code checking can be realized, and the checking efficiency and checking accuracy are improved.

Description

Method, device and computer readable medium for fast checking resource unreleased code
Technical Field
The present application relates to the field of information technologies, and in particular, to a method, an apparatus, and a computer readable medium for quickly checking a code that does not release resources.
Background
In the software development process, the operation of resources such as files, streams, database connection and the like is a problem frequently encountered in development, but the resources cannot be automatically released after use, and the resources should be closed by corresponding closing statements after the use is completed, otherwise, the resources can not be released, so that memory is exhausted, and program and system crashes are caused.
Since such problems in program code are not grammatical errors and are not exposed during the compilation process, it is also difficult to find such problems through conventional testing, and a large number of data stress tests are required to trigger anomalies caused by such problems. Thus, program code with such problems can easily pass testing, and the actual production environment is brought on-line, thereby creating serious problems. In order to avoid similar problems, in general, code content is manually checked by a code developer according to the code capability of the code developer and the judgment of a service scene by mainly releasing the code specification to the developer, so as to find out the problem that resources in the code are not released. But this approach tends to be time consuming and is prone to omission.
Disclosure of Invention
Aspects of the present application provide a method, apparatus, and computer readable medium for rapidly checking a code whose resources are not released, so as to solve the problems of the current scheme that the time consumption is relatively large and omission is easy to occur.
In one aspect of the present application, a method for rapidly checking a resource unreleased code is provided, where the method includes:
generating an abstract syntax tree according to the code file to be checked;
searching a resource operation object in the abstract syntax tree;
if the resource operation object is found, searching a target variable pointed by the resource operation object after instantiation in the abstract syntax tree;
searching a final module containing a resource closing statement corresponding to a target variable in the abstract syntax tree;
if the final module containing the resource closing statement corresponding to the target variable is not found, determining that the risk of unreleased resources exists in the code file.
Based on another aspect of the present application, there is also provided an apparatus for rapidly checking a resource unreleased code, wherein the apparatus includes:
the grammar tree generation module is used for generating an abstract grammar tree according to the code file to be checked;
the object searching module is used for searching a resource operation object in the abstract syntax tree;
the variable searching module is used for searching a target variable pointed by the resource operation object after instantiation in the abstract syntax tree when the resource operation object is searched;
and the closing statement searching module is used for searching a final module containing the resource closing statement corresponding to the target variable in the abstract syntax tree, and determining that the risk of unreleased resources exists in the code file when the final module containing the resource closing statement corresponding to the target variable is not searched.
The embodiment of the application also provides electronic equipment, which comprises:
at least one processor; and
a memory communicatively coupled to the at least one processor; wherein,,
the memory stores instructions executable by the at least one processor to enable the at least one processor to perform the aforementioned method of rapidly troubleshooting resource unreleased code.
Embodiments of the present application also provide a computer readable medium having stored thereon computer program instructions executable by a processor to implement the foregoing method of rapidly troubleshooting resource unreleased code.
In the scheme for rapidly checking the unreleased code of the resource, firstly, an abstract syntax tree is generated according to the code file to be checked, then, resource operation objects are searched in the abstract syntax tree, if the resource operation objects are searched, target variables pointed by the resource operation objects after instantiation are continuously searched in the abstract syntax tree, then, a final module containing a resource closing statement corresponding to the target variables is further searched, when the final module containing the resource closing statement corresponding to the target variables is not searched, the risk of unreleased resource in the code file can be confirmed, and otherwise, the risk of unreleased resource can be eliminated, so that automatic code checking can be realized, checking efficiency and checking accuracy can be improved, development waiting time caused by manual checking can be reduced, code development efficiency can be improved, errors caused by manual checking can be reduced when products are online, and various problems are avoided after the codes are online in a real production environment.
Drawings
In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings used in the embodiments or the description of the prior art will be briefly described below, and it is obvious that the drawings in the following description are some embodiments of the present application, and other drawings may be obtained according to these drawings without inventive effort to a person skilled in the art. Other features, objects and advantages of the present application will become more apparent upon reading of the detailed description of non-limiting embodiments, made with reference to the accompanying drawings in which:
FIG. 1 is a process flow diagram of a method for quickly checking a code that is not released from a resource according to an embodiment of the present application;
FIG. 2 is a flow chart of a process for implementing risk assessment using the method of an embodiment of the present application;
fig. 3 is a schematic structural diagram of an apparatus for quickly checking a code that does not release resources according to an embodiment of the present application;
FIG. 4 is a schematic diagram of an electronic device suitable for implementing an embodiment of the present application;
the same or similar reference numbers in the drawings refer to the same or similar parts.
Detailed Description
For the purpose of making the objects, technical solutions and advantages of the embodiments of the present application more apparent, the technical solutions of the embodiments of 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 embodiments of the present application, but not all embodiments of the present application. All other embodiments, which can be made by those skilled in the art based on the embodiments of the application without making any inventive effort, are intended to be within the scope of the application.
In one exemplary configuration of the application, the terminal, the devices of the services network each include one or more processors (CPUs), input/output interfaces, network interfaces, and memory.
The memory may include volatile memory in a computer-readable medium, random Access Memory (RAM) and/or nonvolatile memory, such as Read Only Memory (ROM) or flash memory (flash RAM). Memory is an example of computer-readable media.
Computer-readable media include both permanent and non-permanent, removable and non-removable media, and information storage may be implemented by any method or technology. The information may be computer program instructions, data structures, modules of the program, or other data. Examples of storage media for a computer include, but are not limited to, phase change memory (PRAM), static Random Access Memory (SRAM), dynamic Random Access Memory (DRAM), other types of Random Access Memory (RAM), read Only Memory (ROM), electrically Erasable Programmable Read Only Memory (EEPROM), flash memory or other memory technology, compact disc read only memory (CD-ROM), digital Versatile Discs (DVD) or other optical storage, magnetic cassettes, magnetic tape storage or other magnetic storage devices, or any other non-transmission medium which can be used to store information that can be accessed by a computing device.
The embodiment of the application provides a method for rapidly checking unreleased codes of resources, which comprises the steps of firstly generating an abstract syntax tree according to code files to be checked, then searching a resource operation object in the abstract syntax tree, and continuously searching a target variable pointed by the resource operation object after instantiation in the abstract syntax tree if the resource operation object is searched; if the target variable pointed by the resource operation object after instantiation is found, further searching a final module containing a resource closing statement corresponding to the target variable in the abstract syntax tree, when the final module containing the resource closing statement corresponding to the target variable is not found, confirming that the risk of unreleased resources exists in the code file, otherwise, eliminating the risk of unreleased resources, thereby realizing automatic code checking, improving checking efficiency and checking accuracy, reducing development waiting time caused by manual checking in the development process, improving code development efficiency, reducing error omission caused by manual checking when products are online, and avoiding various problems caused by the codes after the actual production environment is online
In an actual scenario, the execution body of the method may be a user device, or a device formed by integrating the user device and a network device through a network, or may also be an application running on the device, where the user device includes, but is not limited to, various terminal devices such as a computer, a mobile phone, a tablet computer, and the network device includes, but is not limited to, a network host, a single network server, a plurality of network server sets, or a computer set based on cloud computing. Here, the Cloud is composed of a large number of hosts or web servers based on Cloud Computing (Cloud Computing), which is a kind of distributed Computing, one virtual computer composed of a group of loosely coupled computer sets.
Fig. 1 shows a process flow of a method for quickly checking a code that does not release resources, which may at least include the following processing steps:
step S101, generating an abstract syntax tree according to the code file to be checked. Wherein the abstract syntax tree (Abstract Syntax Tree, AST) is an abstract representation of the syntax structure of the program source code, which represents the syntax structure of the programming language in tree form, each node on the abstract syntax tree representing a part of the content in the source code.
In an actual scenario, a user may preset a source of a code file according to a requirement of an application scenario, for example, the code file to be examined may be from a code repository. Thus, the present embodiment can acquire a code file concerning the source code to be examined from the code repository. After the code files are obtained, the paths of the code files can be added to a file list to be analyzed, each code file in the file list to be analyzed is traversed, and each code file is constructed into an abstract syntax tree.
Taking Java code as an example, the present embodiment can acquire a packet of source code of an item from a code repository by using a data acquisition command. Then, searching a file of the suffix of the java in the data packet of the item, wherein the searched java file is the code file to be checked at the time. Adding the found paths of the java files into a file list to be analyzed, and processing each java file in the file list to be analyzed in a traversing manner, so as to construct an abstract syntax tree about each java file.
Step S102, searching a resource operation object in the abstract syntax tree. The resource operation object is an operation performed on various resources in the source code, for example, the resource operation object in this embodiment may at least include the following: fileReaderFileWriter, fileOutputStream, objectOutputStream, connection object, and the like.
When the resource operation object is searched in the abstract syntax tree, matching can be carried out in the abstract syntax tree through an Xpath. The XPath is a language for searching information in an XML (Extensible Markup Language ) document, and because the abstract syntax tree generally adopts an XML format, the XPath can be used for traversing nodes in the abstract syntax tree, so that the purpose of searching resource operation objects is realized. Taking the foregoing scenario as an example, the matching statement of the corresponding Xpath may be: the term "/ClassOrterface type" means a path searched in an abstract syntax tree, "[ containers (@ image resource operation object) ]" means that the searched content is a resource operation object, and the resource operation object may be specifically FileReaderFileWriter, fileOutputStream, objectOutputStream and connectionResultset described above. In an actual scenario, a plurality of corresponding abstract syntax trees are generated based on a plurality of code files, and then the abstract syntax trees can be traversed in this step, so as to find resource operation objects one by one.
Step S103, if the resource operation object is found, the target variable pointed by the resource operation object after instantiation is found in the abstract syntax tree.
For the above-mentioned several resource operation objects, if any one of the abstract syntax tree is included, after the matching is performed by using the Xpath matching statement, the obtained matching result may include the resource operation object, and at this time, it is required to continuously search the abstract syntax tree for the target variable pointed by the resource operation object after instantiation, so as to further determine whether there is a risk of unreleased resource. And when the matching result is empty, the resource operation object is not found. In this case, since there is no operation on the resource, there is no need to shut down the resource, and thus it can be determined that there is no risk of unreleased resource in the code file.
The target variable pointed by the resource operation object after the instantiation refers to a specific variable generated by the instantiation of the related resource operation object after the actual code operation. Take the following code as an example
FileReaderFileWriter ff=new FileReaderFileWriter("filepath");
codeXXX
ff.close();
The purpose of the code segment is to create a resource operation object instance named as ff for file read-write, wherein filepath refers to a path for file read-write, and codeXXX refers to relevant code content of file read-write operation. For the abstract syntax tree of the code, the searching of the target variable pointed to by the resource operation object after instantiation is referred to as searching the variable 'ff'. Similarly, xpath may also be used for matching when looking up the target variable pointed to after instantiation of the resource operation object. In this embodiment, the matching statement of the corresponding Xpath may be: type (container @ Image, resource operand) ]/variabaledeclaratrid/@ Image, whereby matching can be done under a specific path of the abstract syntax tree. Taking the foregoing scenario as an example, when the resource operation object is FileReaderFileWriter, the target variable "ff" can be matched in the abstract syntax tree.
Step S104, searching a final module containing a resource closing statement corresponding to the target variable in the abstract syntax tree.
The resource closing statement corresponding to the target variable refers to code content for closing a variable pointed to by the resource operation object after instantiation, for example, a target variable "ff" corresponding to the aforementioned resource operation object "FileReaderFileWriter", and the corresponding resource closing statement is "ff. The term "complete module" refers to a complete code block in a code, where content of the code that needs to be executed even if some other portion of the code is abnormal is generally written, and a closing statement for closing a resource is generally in the complete module, so in the solution of the embodiment of the present application, it is necessary to search a complete module containing a resource closing statement corresponding to a target variable in an abstract syntax tree to determine whether the resource corresponding to the target variable is closed in the process of executing the code. Specifically, the determination of the search result in this step needs to include two conditions: 1. whether a finaly module is present; 2. whether the final module contains a resource closing statement corresponding to the target variable. Only when both conditions are satisfied, it is determined that the find module containing the resource closing statement corresponding to the target variable is found, and when any one of the conditions is not satisfied, it is determined that the find module containing the resource closing statement corresponding to the target variable is not found.
Specifically, when executing the above processing, the present embodiment may first find a find module in the abstract syntax tree, and if find a find module, then continue to find a resource closing statement corresponding to the target variable in the find module. If the find-only module is not found in the abstract syntax tree or the resource closing statement corresponding to the target variable is not found in the find-only module, determining that the find-only module containing the resource closing statement corresponding to the target variable is not found.
When searching the resource closing statement corresponding to the target variable in the final module, the Xpath can be used for matching. In this embodiment, the matching statement of the corresponding Xpath may be: the matching can be accomplished under a specific path of the abstract syntax tree by// blockstate/finallystate// PrimaryPreflix/name [ con atains (@ Image, target variable pointed to after resource object instantiation, close) ]. The target variables pointed by the resource object after instantiation are the target variables found in the previous step, such as 'ff'. If the matching result is not null, for example, the target variable "ff" may be matched to the corresponding closing statement ff.close (), at this time, there is a resource closing statement corresponding to the target variable in the find module of the checked code. Otherwise, if the matching result is null, the resource closing statement corresponding to the target variable does not exist in the final module of the checked code.
Step S105, if the find module containing the resource closing statement corresponding to the target variable is not found, determining that there is a risk that the resource is not released in the code file. When the find module containing the resource closing statement corresponding to the target variable is not found, there may be two cases. The first case is that the checked code does not have a finall module, and the second case is that the checked code contains the finall module, but the finall module does not have a resource closing statement corresponding to the target variable. In any case, it may be determined that the find module containing the resource closing statement corresponding to the target variable is not found.
When the checked code species has a find module and the find module also contains a resource closing statement corresponding to the target variable, the find module containing the resource closing statement corresponding to the target variable can be determined, so that the resources created when the code runs can be ensured to be closed in the running process, and the risk of unreleased resources in the code file can be determined at the moment.
According to the method, the device and the system, according to the characteristics of the codes related to resource release, the resource operation object is searched firstly, then the instantiated target variable is searched, and then the final module containing the corresponding resource closing statement is searched for the variable, so that a set of code automation searching scheme aiming at the risk of unreleased resources is formed, automatic checking of the codes unreleased resources is realized, checking efficiency and checking accuracy are improved, development waiting time caused by manual checking can be reduced in the development process, code development efficiency is improved, error omission caused by manual checking can be reduced when products are on line, and various problems caused by the codes after the codes are on line in a real production environment are avoided.
In some embodiments of the application, there may be for loops in the code that needs to be checked. The for loop refers to a code block for which a specific loop termination condition and loop body exist. In order to make the matching of the resource closing statement corresponding to the target variable more accurate, it may be searched in the abstract syntax tree before step S102 whether a for loop exists. The searching mode can also use Xpath matching, and the matching statement of the corresponding Xpath can be: block State/ForStatement. If the matching result is null, it means that the for loop is not found, step S102 is directly executed, and the resource operation object is found in the abstract syntax tree.
If the matching result is not null, it means that the for loop is found, and the inside and the outside of the for loop can be treated separately. The code content for the loop body of the for loop is the internal code content of the for loop, and the external code content of the for loop is the rest code content except for the for loop in the code to be checked. For the interior of the for loop, processing similar to steps S102 to S105 may be performed in the interior of the for loop, that is, searching for a resource operation object in the interior of the for loop, if the resource operation object is found in the interior of the for loop, continuing to search for a target variable pointed to after the resource operation object is instantiated in the interior of the for loop, and then searching for a find module containing a resource closing statement corresponding to the target variable in the interior of the for loop.
For the exterior of the for loop, the resource operation object can be searched for at the exterior of the for loop, then the target variable is searched for, and further whether the final module containing the resource closing statement corresponding to the target variable exists or not is judged. If the complete module containing the resource closing statement corresponding to the target variable does not exist in the for loop and outside the for loop, the risk that the resource is not released in the code file can be accurately judged. For the situation that the risk exists, prompt information can be automatically generated to inform a user of the specific situation that the risk exists that the resources are not released, and therefore quick investigation of the risk is achieved.
Fig. 2 shows a process flow when risk investigation is performed on java code by adopting the scheme provided by the embodiment of the application, which comprises the following steps:
step S201, data about the source code is acquired from the code repository by using the data acquisition command.
Step S202, searching a file with a 'java' suffix in the data of the source code, and adding the found path of the java file to a file list to be analyzed.
Step S203, traversing each java file in the file list to be analyzed, and constructing an abstract syntax tree of the java file.
Step S204, find out whether there is for loop in the whole abstract syntax tree. If no for loop exists, the following steps are continued.
In step S205, the Xpath is used to find the resource operation object such as FileReaderFileWriter, fileOutputStream, objectOutputStream and ConnectionResultSet in the abstract syntax tree. If no resource operation object is found in the abstract syntax tree, the source code is indicated to have no resource operation, and therefore, the risk of unreleased resources does not exist.
In step S206, if the resource operation object is found, it is indicated that there is a resource operation in the source code, and analysis needs to be continued on the abstract code tree, so that the target variable pointed to after the instantiation of the operation resource object can be continuously searched from the abstract syntax tree.
In step S207, it is determined whether there is a finaly module, and if there is no finaly module, it is determined that there is a risk that resources are not released. If the finaly module exists, the step S209 is continued.
Whether the find final module in step S208 contains a closing statement of the target variable pointed to after the instantiation of the operation resource object. If not, determining that the risk of unreleased resources exists. If yes, determining that the risk of unreleased resources exists is not determined.
If the for loop exists in step S209, steps S205 to S208 may be repeatedly executed within the for loop. Meanwhile, for the outside of the for circulation, the risk investigation based on the method can be also adopted.
In addition, the embodiment of the application also provides a device for quickly checking the code of which the resources are not released, and the structure of the device is shown in fig. 3, and the device comprises a grammar tree generating module 310, an object searching module 320, a variable searching module 330 and a closing statement searching module 340. The syntax tree generating module 310 is configured to generate an abstract syntax tree according to the code file to be examined. The object searching module 320 is configured to search the abstract syntax tree for a resource operation object. The variable searching module 330 is configured to, when searching for a resource operation object, search the abstract syntax tree for a target variable pointed to by the resource operation object after instantiation. The closing statement searching module 340 is configured to search the abstract syntax tree for a final module containing a resource closing statement corresponding to the target variable, and determine that there is a risk that the resource is not released in the code file when the final module containing the resource closing statement corresponding to the target variable is not searched.
Based on the same inventive concept, the embodiment of the application also provides an electronic device, and the corresponding method of the electronic device may be the method for quickly checking the unreleased code of the resource in the foregoing embodiment, and the principle of solving the problem is similar to that of the method. The electronic equipment provided by the embodiment of the application comprises: at least one processor; and a memory communicatively coupled to the at least one processor; wherein the memory stores instructions executable by the at least one processor to enable the at least one processor to perform the methods and/or aspects of the various embodiments of the application described above.
The electronic device may be a user device, or a device formed by integrating the user device and a network device through a network, or may also be an application running on the device, where the user device includes, but is not limited to, various terminal devices such as a computer, a mobile phone, a tablet computer, and the network device includes, but is not limited to, a network host, a single network server, a plurality of network server sets, or a computer set based on cloud computing. Here, the Cloud is composed of a large number of hosts or web servers based on Cloud Computing (Cloud Computing), which is a kind of distributed Computing, one virtual computer composed of a group of loosely coupled computer sets.
Fig. 4 shows a structure of a device suitable for implementing the method and/or technical solution in an embodiment of the present application, the device 400 comprising a central processing unit (CPU, central Processing Unit) 401, which may perform various suitable actions and processes according to a program stored in a Read Only Memory (ROM) 402 or a program loaded from a storage section 408 into a random access Memory (RAM, random Access Memory) 403. In the RAM 403, various programs and data required for the system operation are also stored. The CPU 401, ROM 402, and RAM 403 are connected to each other by a bus 404. An Input/Output (I/O) interface 405 is also connected to bus 404.
The following components are connected to the I/O interface 405: an input section 406 including a keyboard, a mouse, a touch panel, a microphone, an infrared sensor, and the like; an output portion 407 including a display such as a Cathode Ray Tube (CRT), a liquid crystal display (LCD, liquid Crystal Display), an LED display, an OLED display, and a speaker; a storage portion 408 comprising one or more computer-readable media of hard disk, optical disk, magnetic disk, semiconductor memory, etc.; and a communication section 409 including a network interface card such as a LAN (local area network ) card, a modem, or the like. The communication section 409 performs communication processing via a network such as the internet.
In particular, the methods and/or embodiments of the present application may be implemented as computer software programs. For example, embodiments of the present disclosure include a computer program product comprising a computer program embodied on a computer readable medium, the computer program comprising program code for performing the method shown in the flow chart. The above-described functions defined in the method of the present application are performed when the computer program is executed by a Central Processing Unit (CPU) 401.
Another embodiment of the present application also provides a computer readable storage medium having stored thereon computer program instructions executable by a processor to implement the method and/or the technical solution of any one or more of the embodiments of the present application described above.
In particular, the present embodiments may employ any combination of one or more computer-readable media. The computer readable medium may be a computer readable signal medium or a computer readable storage medium. The computer readable storage medium can be, for example, but not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or a combination of any of the foregoing. More specific examples (a non-exhaustive list) of the computer-readable storage medium would include the following: an electrical connection having one or more wires, a portable computer diskette, a hard disk, a Random Access Memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing. In this document, a computer readable storage medium may be any tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device.
The computer readable signal medium may include a propagated data signal with computer readable program code embodied therein, either in baseband or as part of a carrier wave. Such a propagated data signal may take any of a variety of forms, including, but not limited to, electro-magnetic, optical, or any suitable combination of the foregoing. A computer readable signal medium may also be any computer readable medium that is not a computer readable storage medium and that can communicate, propagate, or transport a program for use by or in connection with an instruction execution system, apparatus, or device.
Program code embodied on a computer readable medium may be transmitted using any appropriate medium, including but not limited to wireless, wireline, optical fiber cable, RF, etc., or any suitable combination of the foregoing.
Computer program code for carrying out operations of the present application may be written in any combination of one or more programming languages, including an object oriented programming language such as Java, smalltalk, C ++ and conventional procedural programming languages, such as the "C" programming language or similar programming languages. The program code may execute entirely on the user's computer, partly on the user's computer, as a stand-alone software package, partly on the user's computer and partly on a remote computer or entirely on the remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer through any kind of network, including a Local Area Network (LAN) or a Wide Area Network (WAN), or may be connected to an external computer (for example, through the Internet using an Internet service provider).
The flowchart or block diagrams in the figures illustrate the architecture, functionality, and operation of possible implementations of devices, methods and computer program products according to various embodiments of the present application. In this regard, each block in the flowchart or block diagrams may represent a module, segment, or portion of code, which comprises one or more executable instructions for implementing the specified logical function(s). It should also be noted that, in some alternative implementations, the functions noted in the block may occur out of the order noted in the figures. For example, two blocks shown in succession may, in fact, be executed substantially concurrently, or the blocks may sometimes be executed in the reverse order, depending upon the functionality involved. It will also be noted that each block of the block diagrams and/or flowchart illustration, and combinations of blocks in the block diagrams and/or flowchart illustration, can be implemented by special purpose hardware-based systems which perform the specified functions or acts, or combinations of special purpose hardware and computer instructions.
It will be clear to those skilled in the art that, for convenience and brevity of description, specific working procedures of the above-described systems, apparatuses and units may refer to corresponding procedures in the foregoing method embodiments, which are not repeated herein.
In the several embodiments provided in the present application, it should be understood that the disclosed systems, devices, and methods may be implemented in other manners. For example, the apparatus embodiments described above are merely illustrative, e.g., the division of the elements is merely a logical function division, and there may be additional divisions in actual implementation, e.g., multiple elements or page components may be combined or integrated into another system, or some features may be omitted, or not performed. Alternatively, the coupling or direct coupling or communication connection shown or discussed with each other may be an indirect coupling or communication connection via some interfaces, devices or units, which may be in electrical, mechanical or other form.
The units described as separate units may or may not be physically separate, and units shown as units may or may not be physical units, may be located in one place, or may be distributed on a plurality of network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
In addition, each functional unit in the embodiments of the present application may be integrated in one processing unit, or each unit may exist alone physically, or two or more units may be integrated in one unit. The integrated units may be implemented in hardware or in hardware plus software functional units.
The integrated units implemented in the form of software functional units described above may be stored in a computer readable storage medium. The software functional unit is stored in a storage medium, and includes several instructions for causing a computer device (which may be a personal computer, a server, or a network device, etc.) or a processor (processor) to perform part of the steps of the methods described in 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 (Random Access Memory, RAM), a magnetic disk, or an optical disk, or other various media capable of storing program codes.
Finally, it should be noted that: the above embodiments are only for illustrating the technical solution of the present application, and are not limiting; although the application has been described in detail with reference to the foregoing embodiments, it will 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 technical solutions of the embodiments of the present application.
Furthermore, it is evident that the word "comprising" does not exclude other elements or steps, and that the singular does not exclude a plurality. A plurality of units or means recited in the apparatus claims can also be implemented by means of one unit or means in software or hardware. The terms first, second, etc. are used to denote a name, but not any particular order.

Claims (11)

1. A method for quickly checking for unreleased codes of resources, wherein the method comprises:
generating an abstract syntax tree according to the code file to be checked;
searching a resource operation object in the abstract syntax tree;
if the resource operation object is found, searching a target variable pointed by the resource operation object after instantiation in the abstract syntax tree;
searching a final module containing a resource closing statement corresponding to a target variable in the abstract syntax tree;
if the final module containing the resource closing statement corresponding to the target variable is not found, determining that the risk of unreleased resources exists in the code file.
2. The method of claim 1, wherein generating an abstract syntax tree from the code file that is to be examined comprises:
acquiring a code file of a source code to be checked from a code warehouse;
adding the path of the code file to a file list to be analyzed;
traversing each code file in the file list to be analyzed, and constructing each code file into an abstract syntax tree.
3. The method of claim 1, wherein the method further comprises:
and if the resource operation object is not found, determining that the risk of unreleased resources does not exist in the code file.
4. The method of claim 1, wherein looking up resource operation objects in the abstract syntax tree comprises:
searching for a for loop in the abstract syntax tree;
if the for loop is not found, searching the resource operation object in the abstract syntax tree.
5. The method of claim 1, wherein looking up resource operation objects in the abstract syntax tree comprises:
searching for a for loop in the abstract syntax tree;
if the for loop is found, searching the resource operation object in the for loop.
6. The method of claim 5, wherein the method further comprises:
if the for loop is found, searching the resource operation object outside the for loop.
7. The method of claim 1, wherein searching the abstract syntax tree for a final module containing a resource closing statement corresponding to a target variable comprises:
searching a find module in the abstract syntax tree;
if a final module is found, searching a resource closing statement corresponding to a target variable in the final module;
if the find-only module is not found in the abstract syntax tree or the resource closing statement corresponding to the target variable is not found in the find-only module, determining that the find-only module containing the resource closing statement corresponding to the target variable is not found.
8. The method of claim 1, wherein the method further comprises:
if find out the final module comprising resource closing statement that the target variable corresponds to, confirm that there is not the risk that the resource is unreleased in the said code file.
9. An apparatus for fast checking for unreleased codes of resources, wherein the apparatus comprises:
the grammar tree generation module is used for generating an abstract grammar tree according to the code file to be checked;
the object searching module is used for searching a resource operation object in the abstract syntax tree;
the variable searching module is used for searching a target variable pointed by the resource operation object after instantiation in the abstract syntax tree when the resource operation object is searched;
and the closing statement searching module is used for searching a final module containing the resource closing statement corresponding to the target variable in the abstract syntax tree, and determining that the risk of unreleased resources exists in the code file when the final module containing the resource closing statement corresponding to the target variable is not searched.
10. An electronic device, the electronic device comprising:
at least one processor; and
a memory communicatively coupled to the at least one processor; wherein,,
the memory stores instructions executable by the at least one processor to enable the at least one processor to perform the method of any one of claims 1 to 8.
11. A computer readable medium having stored thereon computer program instructions executable by a processor to implement the method of any of claims 1 to 8.
CN202310754180.1A 2023-06-25 2023-06-25 Method, device and computer readable medium for fast checking resource unreleased code Pending CN116881129A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202310754180.1A CN116881129A (en) 2023-06-25 2023-06-25 Method, device and computer readable medium for fast checking resource unreleased code

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202310754180.1A CN116881129A (en) 2023-06-25 2023-06-25 Method, device and computer readable medium for fast checking resource unreleased code

Publications (1)

Publication Number Publication Date
CN116881129A true CN116881129A (en) 2023-10-13

Family

ID=88262700

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202310754180.1A Pending CN116881129A (en) 2023-06-25 2023-06-25 Method, device and computer readable medium for fast checking resource unreleased code

Country Status (1)

Country Link
CN (1) CN116881129A (en)

Similar Documents

Publication Publication Date Title
US9465608B2 (en) Code separation with semantic guarantees
US10061573B2 (en) User interfaces of application porting software platform
US10019259B2 (en) Code transformation using extensibility libraries
CN110865889B (en) Method and device for transmitting event between components
CN109634587B (en) Method and equipment for generating warehousing script and warehousing data
US10572371B2 (en) Generating valid use cases from a parsed configuration file describing use case options
US20160321218A1 (en) System and method for transforming image information for a target system interface
US20170054790A1 (en) System and Method for Object Compression and State Synchronization
WO2021228036A1 (en) Modification of codified infrastructure for orchestration in multi-cloud environment
US9652358B1 (en) Type widening for source code analysis
CN110727476B (en) Method, device, equipment and storage medium for generating authorization configuration file
US10409590B2 (en) Creation and execution of customised code for a data processing platform
CN110688111A (en) Configuration method, device, server and storage medium of business process
WO2015003452A1 (en) Methods and systems for file processing
CN116028028A (en) Request function generation method, device, equipment and storage medium
US20150020056A1 (en) Methods and systems for file processing
CN113238739A (en) Plug-in development and data acquisition method, device, electronic equipment and medium
CN113377342B (en) Project construction method and device, electronic equipment and storage medium
CN117632710A (en) Method, device, equipment and storage medium for generating test code
CN111240987B (en) Method and device for detecting migration program, electronic equipment and computer readable storage medium
CN112988578A (en) Automatic testing method and device
US20140137083A1 (en) Instrumenting computer program code by merging template and target code methods
JP2020129359A (en) Method, apparatus, facility, and medium for managing knowledge base
CN116881129A (en) Method, device and computer readable medium for fast checking resource unreleased code
CN112947941A (en) Method and device for adding exception handling code

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