Skip to main content
Glama

analyze_memory_safety

Analyze C++ code to detect memory safety issues like leaks, dangling pointers, and unsafe operations, generating a detailed report for code review.

Instructions

分析 C++ 代码中的内存安全问题 参数: code: 要分析的 C++ 代码 返回: 内存安全分析报告,包括潜在的内存泄漏、悬空指针、不安全操作等

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
codeYes

Implementation Reference

  • MCP tool registration via @mcp.tool() decorator for the analyze_memory_safety tool.
    @mcp.tool() def analyze_memory_safety(code: str) -> str: """ 分析 C++ 代码中的内存安全问题 参数: code: 要分析的 C++ 代码 返回: 内存安全分析报告,包括潜在的内存泄漏、悬空指针、不安全操作等 """ analyzer = get_memory_analyzer() issues, report = analyzer.analyze_memory_safety(code) return report
  • Handler function that executes the tool logic by delegating to the MemorySafetyAnalyzer and returning the formatted report.
    @mcp.tool() def analyze_memory_safety(code: str) -> str: """ 分析 C++ 代码中的内存安全问题 参数: code: 要分析的 C++ 代码 返回: 内存安全分析报告,包括潜在的内存泄漏、悬空指针、不安全操作等 """ analyzer = get_memory_analyzer() issues, report = analyzer.analyze_memory_safety(code) return report
  • Main helper method in MemorySafetyAnalyzer that orchestrates checks for raw pointers, manual memory management, array access, unsafe strings, leaks, double deletes, and dangling pointers using regex-based analysis.
    def analyze_memory_safety(self, code: str) -> Tuple[List[Dict], str]: """ 分析代码中的内存安全问题 Args: code: 要分析的 C++ 代码 Returns: (问题列表, 格式化的分析报告) """ issues = [] # 检查各种内存安全问题 issues.extend(self._check_raw_pointers(code)) issues.extend(self._check_manual_memory(code)) issues.extend(self._check_array_access(code)) issues.extend(self._check_string_operations(code)) issues.extend(self._check_resource_leaks(code)) issues.extend(self._check_double_delete(code)) issues.extend(self._check_dangling_pointers(code)) # 生成报告 report = self._generate_report(issues, code) return issues, report
  • Factory function providing singleton instance of the MemorySafetyAnalyzer, imported and aliased as get_memory_analyzer in server.py.
    def get_analyzer() -> MemorySafetyAnalyzer: """获取全局内存安全分析器实例""" global _analyzer if _analyzer is None: _analyzer = MemorySafetyAnalyzer() return _analyzer

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/SongJiangzhou/cpp_guidelines'

If you have feedback or need assistance with the MCP directory API, please join our Discord server