|
| 1 | +# Memory Verifier |
| 2 | + |
| 3 | +**Standalone tool to verify your curl/OpenSSL configuration has no memory leaks.** |
| 4 | + |
| 5 | +## Quick Start |
| 6 | + |
| 7 | +```bash |
| 8 | +cd memory-verifier |
| 9 | +make run |
| 10 | +``` |
| 11 | + |
| 12 | +## Purpose |
| 13 | + |
| 14 | +This is a **completely separate test application** that verifies your curl 7.81.0 + OpenSSL 3.0.2 setup has no memory leaks. It's independent from the main telemetry leak detection tests. |
| 15 | + |
| 16 | + |
| 17 | +## What It Does |
| 18 | + |
| 19 | +Runs multiple independent verification tests, matching production and edge-case usage: |
| 20 | + |
| 21 | +### Standard Tests |
| 22 | + |
| 23 | +- **Version Check**: Validates your libcurl and OpenSSL versions for known issues. |
| 24 | +- **Connection Pool Pattern**: Simulates production connection pool usage with detailed per-iteration memory tracking. Pool size is configurable via `T2_CONNECTION_POOL_SIZE`. |
| 25 | +- **POST Memory Leak Test**: Runs 100 POST requests to detect memory growth in typical POST usage. |
| 26 | + |
| 27 | +### Valgrind-Integrated Tests |
| 28 | + |
| 29 | +- **Valgrind Pool Test**: Runs the connection pool pattern under Valgrind to detect leaks and profile operational memory usage. |
| 30 | +- **Valgrind SSL/OpenSSL Investigation**: Deep-dive memory profiling of SSL/OpenSSL usage, focusing on known memory growth patterns. |
| 31 | + |
| 32 | +### Logging & Analysis |
| 33 | + |
| 34 | +- Per-iteration logs: `connection_pool_iterations.log` for detailed memory and operation tracking. |
| 35 | +- Valgrind and Massif outputs: `valgrind_pool_baseline.log`, `massif_pool_baseline.out`, `massif_ssl_investigation.out`, and human-readable reports if `ms_print` is available. |
| 36 | + |
| 37 | +### Environment Variables |
| 38 | + |
| 39 | +- `T2_CONNECTION_POOL_SIZE`: Set the connection pool size (default: 2, min: 1, max: 5). |
| 40 | +- `T2_TEST_ITERATIONS`: Set the number of pool test iterations (default: 50, max: 200). |
| 41 | +- `VALGRIND_FAST_MODE`: If set, reduces iterations and delays for faster Valgrind runs. |
| 42 | + |
| 43 | +### CLI Options (see `--help`) |
| 44 | + |
| 45 | +``` |
| 46 | + --version, -v Run version-specific assessment |
| 47 | + --pool, -p Run connection pool pattern test |
| 48 | + --post, -o Run POST memory leak test |
| 49 | + --valgrind-pool Valgrind analysis of pool without reset |
| 50 | + --valgrind-ssl Investigate SSL/OpenSSL memory patterns |
| 51 | + --all, -a Run all standard tests (default) |
| 52 | + --all-valgrind Run all valgrind-integrated tests |
| 53 | + --help Show help message with all options |
| 54 | +``` |
| 55 | + |
| 56 | +See the source or run `./memory_verifier --help` for the full list of options and examples. |
| 57 | + |
| 58 | + |
| 59 | +## Expected Results |
| 60 | + |
| 61 | +✅ **Success (No Leaks):** |
| 62 | +``` |
| 63 | +��� FINAL VERIFICATION RESULT |
| 64 | +Tests Run: <N> |
| 65 | +Passed: <N> |
| 66 | +Failed: 0 |
| 67 | +
|
| 68 | +✅ VERDICT: NO MEMORY LEAKS DETECTED |
| 69 | +��� YOUR HTTP CLIENT IS PRODUCTION-READY! |
| 70 | +``` |
| 71 | + |
| 72 | +⚠️ **Acceptable (Monitor):** |
| 73 | +- Some warnings but no failures |
| 74 | +- Memory growth within acceptable thresholds (see logs for details) |
| 75 | + |
| 76 | +❌ **Issues Found:** |
| 77 | +- Test failures indicate potential memory problems |
| 78 | +- Requires investigation (see Valgrind logs and summary) |
| 79 | + |
| 80 | +## Directory Structure |
| 81 | + |
| 82 | +``` |
| 83 | +memory-verifier/ # <- You are here |
| 84 | +├── memory_verifier.c # Standalone verification tool |
| 85 | +├── Makefile # Independent build system |
| 86 | +└── README.md # This file |
| 87 | +
|
| 88 | +../leak_detection/ # <- Your main test suite (separate) |
| 89 | +├── curl_leak_test.c # Main telemetry tests |
| 90 | +├── multicurlinterface.c # Your fixed HTTP client |
| 91 | +└── Makefile # Main test build system |
| 92 | +``` |
| 93 | + |
| 94 | + |
| 95 | +## Build & Run |
| 96 | + |
| 97 | +```bash |
| 98 | +make # Build only |
| 99 | +make run # Build and run (recommended) |
| 100 | +make clean # Clean build artifacts |
| 101 | +make help # Show detailed help |
| 102 | + |
| 103 | + |
| 104 | +# Run with custom options |
| 105 | +./memory_verifier --pool # Run connection pool test |
| 106 | +T2_CONNECTION_POOL_SIZE=3 ./memory_verifier --pool # Pool size 3 |
| 107 | +T2_TEST_ITERATIONS=100 ./memory_verifier --pool # 100 iterations |
| 108 | +./memory_verifier --valgrind-pool # Valgrind pool analysis |
| 109 | +./memory_verifier --valgrind-ssl # Deep SSL/OpenSSL investigation |
| 110 | + |
| 111 | +# Automated Dynamic Analysis (GDB/SSL investigation) |
| 112 | +./run_dynamic_analysis.sh # Run automated dynamic SSL/OpenSSL memory analysis |
| 113 | +./run_dynamic_analysis.sh --help # Show script options and usage |
| 114 | +``` |
| 115 | + |
| 116 | + |
| 117 | +## Integration & Analysis |
| 118 | + |
| 119 | + |
| 120 | +This tool is **completely independent** from your main telemetry code. |
| 121 | + |
| 122 | +- **For production verification**: Use this tool |
| 123 | +- **For telemetry testing**: Use `../leak_detection/` |
| 124 | +- **For detailed analysis**: Use `cd ../leak_detection && make valgrind` |
| 125 | +- **For automated dynamic SSL/OpenSSL analysis**: Use `run_dynamic_analysis.sh` (runs GDB-based tracing, logging, and summary for SSL memory investigation) |
| 126 | + |
| 127 | + |
| 128 | +### Log Files & Outputs |
| 129 | + |
| 130 | +- `connection_pool_iterations.log`: Per-iteration memory and operation log |
| 131 | +- `valgrind_pool_baseline.log`: Valgrind leak report for pool test |
| 132 | +- `massif_pool_baseline.out`: Massif memory profile for pool test |
| 133 | +- `massif_ssl_investigation.out`: Massif memory profile for SSL investigation |
| 134 | +- `massif_ssl_report.txt`: Human-readable SSL memory profile (if `ms_print` is available) |
| 135 | +- `dynamic_analysis.log`: Main log for run_dynamic_analysis.sh (GDB/SSL trace summary) |
| 136 | +- `dynamic_analysis_summary.log`: High-level summary of dynamic analysis results |
| 137 | +## run_dynamic_analysis.sh |
| 138 | + |
| 139 | +This script automates dynamic SSL/OpenSSL memory analysis using GDB. It runs the memory_verifier in a controlled environment, traces SSL/OpenSSL allocation functions, and summarizes memory growth and leak patterns. |
| 140 | + |
| 141 | +**Usage:** |
| 142 | + |
| 143 | +```bash |
| 144 | +./run_dynamic_analysis.sh # Run full dynamic analysis suite |
| 145 | +./run_dynamic_analysis.sh --help # Show all options and usage |
| 146 | +``` |
| 147 | + |
| 148 | +**Features:** |
| 149 | +- Automated GDB tracing of SSL/OpenSSL allocation and cleanup functions |
| 150 | +- Per-iteration and summary logging |
| 151 | +- Timeout and iteration controls (via environment variables) |
| 152 | +- Correlates memory growth with SSL connection pool operations |
| 153 | +- Produces logs for management and engineering review |
| 154 | + |
| 155 | +See the script header or run with `--help` for full details and advanced options. |
| 156 | + |
| 157 | + |
| 158 | +## Requirements |
| 159 | + |
| 160 | +- Linux environment (WSL2 supported) |
| 161 | +- libcurl development headers |
| 162 | +- Valgrind (for valgrind-integrated tests) |
| 163 | +- Internet connection (tests use httpbin.org) |
| 164 | + |
| 165 | +## Troubleshooting & Tips |
| 166 | + |
| 167 | +- If you see memory growth, check the logs and Valgrind output for SSL/OpenSSL or curl-related leaks. |
| 168 | +- Use environment variables to tune pool size and iteration count for your environment. |
| 169 | +- For deep SSL/OpenSSL memory analysis, use the `--valgrind-ssl` option and review `massif_ssl_report.txt`. |
| 170 | + |
| 171 | +For full CLI usage and test descriptions, run: |
| 172 | + |
| 173 | +```bash |
| 174 | +./memory_verifier --help |
| 175 | +``` |
0 commit comments