The invention provides an automatic detection and positioning method for a memory error in a source code. The method comprises the steps of firstly using a compiler for carrying out lexical analysis and grammatical analysis on the source code, and constructing a symbol table and an abstract syntax tree; then through traversing the abstract syntax tree, carrying out source code transformation on a node which may produce the memory error, and finally compiling and executing the source code subjected to transformation, wherein a program can automatically judge the occurrence of the memory error, and accurately reports a source code position corresponding to the error. The automatic detection and positioning method for the memory error in the source code provided by the invention can be used for accurately automatically detecting and positioning the memory error so as to realize more comprehensive error detection, better compatibility, better platform universality, more accurate source code positioning, and higher runtime performance and efficiency, so that the quality of software and the efficiency of software maintenance are improved.