Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 73 additions & 0 deletions leaktestapp/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
CC = gcc
CFLAGS = -Wall -Wextra -g -O0
LDFLAGS = -lcurl -lpthread

TARGET = memory_verifier

.PHONY: all clean run help valgrind-investigate

all: $(TARGET)
@echo ""
@echo "✓ Memory Verifier built successfully: $(TARGET)"
@echo " Run with: make run"
@echo ""

$(TARGET): memory_verifier.c
$(CC) $(CFLAGS) -o $(TARGET) memory_verifier.c $(LDFLAGS)

run: $(TARGET)
@echo "🔍 Running Memory Leak Verification..."
@echo ""
./$(TARGET)

valgrind-investigate: $(TARGET)
@echo "🧪 Running SSL Memory Investigation..."
@echo ""
@if [ -f "investigate_ssl_memory.sh" ]; then \
chmod +x investigate_ssl_memory.sh 2>/dev/null || true; \
./investigate_ssl_memory.sh; \
elif [ -f "investigate_ssl_memory.bat" ]; then \
cmd //c investigate_ssl_memory.bat; \
else \
echo "❌ Investigation script not found"; \
exit 1; \
fi

clean:
rm -f $(TARGET)
rm -f *.log *.out *.txt valgrind_*.sh
@echo "✓ Cleaned memory verifier and investigation files"

help:
@echo "Memory Leak Verifier with Valgrind Integration"
@echo "=============================================="
@echo ""
@echo "Standalone tool to verify curl/OpenSSL has no memory leaks"
@echo ""
@echo "Commands:"
@echo " make - Build the verifier"
@echo " make run - Build and run verification (RECOMMENDED)"
@echo " make valgrind-investigate - Run SSL memory investigation (NEW)"
@echo " make clean - Remove build artifacts and logs"
@echo " make help - Show this help"
@echo ""
@echo "Quick Start:"
@echo " make run # Standard memory verification"
@echo " make valgrind-investigate # Investigate SSL memory increase"
@echo ""
@echo "Standard Tests:"
@echo " ✓ Basic HTTP client memory growth"
@echo " ✓ Handle reuse and connection pooling"
@echo " ✓ Memory stability over time"
@echo " ✓ Library version compatibility"
@echo ""
@echo "NEW: Valgrind Investigation (for SSL 3484KB→3608KB issue):"
@echo " ✓ Pool baseline analysis"
@echo " ✓ Reset fix impact analysis"
@echo " ✓ Comparative leak assessment"
@echo " ✓ SSL/OpenSSL deep investigation"
@echo ""
@echo "Individual Valgrind Tests:"
@echo " ./memory_verifier --valgrind-pool # Baseline"
@echo " ./memory_verifier --valgrind-reset # Reset fix"
@echo " ./memory_verifier --post-analysis # Compare"
Comment on lines +70 to +73
Copy link

Copilot AI Mar 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Makefile help suggests CLI options (--valgrind-reset, --post-analysis) that memory_verifier doesn’t currently implement/parse. Please keep Makefile help aligned with actual supported options, otherwise users will hit “Unknown argument”.

Suggested change
@echo "Individual Valgrind Tests:"
@echo " ./memory_verifier --valgrind-pool # Baseline"
@echo " ./memory_verifier --valgrind-reset # Reset fix"
@echo " ./memory_verifier --post-analysis # Compare"
@echo "Note:"
@echo " Valgrind-based SSL memory investigations are driven via:"
@echo " make valgrind-investigate"
@echo " (see investigate_ssl_memory.sh/.bat for detailed steps)"

Copilot uses AI. Check for mistakes.
166 changes: 166 additions & 0 deletions leaktestapp/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
# Memory Verifier

**Standalone tool to verify your curl/OpenSSL configuration to check memory leaks.**

## Quick Start

```bash
cd memory-verifier
Copy link

Copilot AI Mar 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

README quick start and paths don’t match the repo layout: this directory is leaktestapp/, but the instructions say cd memory-verifier. Please update the path so a user can follow the steps from the repo root without guessing.

Suggested change
cd memory-verifier
cd leaktestapp

Copilot uses AI. Check for mistakes.
make run
```

## Purpose

Comment on lines +7 to +13
Copy link

Copilot AI Mar 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

README references a different directory name (memory-verifier/) and a script named run_dynamic_analysis.sh, but the repo path here is leaktestapp/ and the script added is run_gdb_dynamic_analysis.sh. Update the README commands/paths to match the actual layout and filenames so the quick-start instructions work.

Copilot uses AI. Check for mistakes.
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.


## What It Does

Runs multiple independent verification tests, matching production and edge-case usage:

### Standard Tests

- **Version Check**: Validates your libcurl and OpenSSL versions for known issues.
- **Connection Pool Pattern**: Simulates production connection pool usage with detailed per-iteration memory tracking. Pool size is configurable via `T2_CONNECTION_POOL_SIZE`.
- **POST Memory Leak Test**: Runs 100 POST requests to detect memory growth in typical POST usage.

### Valgrind-Integrated Tests

- **Valgrind Pool Test**: Runs the connection pool pattern under Valgrind to detect leaks and profile operational memory usage.
- **Valgrind SSL/OpenSSL Investigation**: Deep-dive memory profiling of SSL/OpenSSL usage, focusing on known memory growth patterns.

### Logging & Analysis

- Per-iteration logs: `connection_pool_iterations.log` for detailed memory and operation tracking.
- 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.

### Environment Variables

- `T2_CONNECTION_POOL_SIZE`: Set the connection pool size (default: 2, min: 1, max: 5).
- `T2_TEST_ITERATIONS`: Set the number of pool test iterations (default: 50, max: 200).
- `VALGRIND_FAST_MODE`: If set, reduces iterations and delays for faster Valgrind runs.

### CLI Options (see `--help`)

```
--version, -v Run version-specific assessment
--pool, -p Run connection pool pattern test
--post, -o Run POST memory leak test
--valgrind-pool Valgrind analysis of pool without reset
--valgrind-ssl Investigate SSL/OpenSSL memory patterns
--all, -a Run all standard tests (default)
--all-valgrind Run all valgrind-integrated tests
--help Show help message with all options
```

See the source or run `./memory_verifier --help` for the full list of options and examples.


## Expected Results

✅ **Success (No Leaks):**
```
��� FINAL VERIFICATION RESULT
Tests Run: <N>
Passed: <N>
Failed: 0

✅ VERDICT: NO MEMORY LEAKS DETECTED
��� YOUR HTTP CLIENT IS PRODUCTION-READY!
```

⚠️ **Acceptable (Monitor):**
- Some warnings but no failures
- Memory growth within acceptable thresholds (see logs for details)

❌ **Issues Found:**
- Test failures indicate potential memory problems
- Requires investigation (see Valgrind logs and summary)

## Directory Structure

```
memory-verifier/ # <- You are here
├── memory_verifier.c # Standalone verification tool
├── Makefile # Independent build system
└── README.md # This file


## Build & Run

```bash
make # Build only
Comment on lines +80 to +92
Copy link

Copilot AI Mar 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Markdown code fences for “Directory Structure” / “Build & Run” appear unbalanced (a ``` block opens at “Directory Structure” but isn’t closed before “Build & Run”). This causes rendering issues on GitHub. Please close/open code fences appropriately.

Copilot uses AI. Check for mistakes.
make run # Build and run (recommended)
make clean # Clean build artifacts
make help # Show detailed help
Comment on lines +7 to +95


# Run with custom options
./memory_verifier --pool # Run connection pool test
T2_CONNECTION_POOL_SIZE=2 ./memory_verifier --pool # Pool size 3
Copy link

Copilot AI Mar 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The example T2_CONNECTION_POOL_SIZE=2 ./memory_verifier --pool is annotated as “Pool size 3”, which is inconsistent with the env var value. Please fix the comment/example so users don’t misconfigure the pool size.

Suggested change
T2_CONNECTION_POOL_SIZE=2 ./memory_verifier --pool # Pool size 3
T2_CONNECTION_POOL_SIZE=2 ./memory_verifier --pool # Pool size 2

Copilot uses AI. Check for mistakes.
T2_TEST_ITERATIONS=100 ./memory_verifier --pool # 100 iterations
./memory_verifier --valgrind-pool # Valgrind pool analysis
./memory_verifier --valgrind-ssl # Deep SSL/OpenSSL investigation

```


## Integration & Analysis


This tool is **completely independent** from your main telemetry code.

- **For production verification**: Use this tool
- **For telemetry testing**: Use `../leak_detection/`
- **For detailed analysis**: Use `cd ../leak_detection && make valgrind`
- **For automated dynamic SSL/OpenSSL analysis**: Use `run_dynamic_analysis.sh` (runs GDB-based tracing, logging, and summary for SSL memory investigation)


### Log Files & Outputs

- `connection_pool_iterations.log`: Per-iteration memory and operation log
- `valgrind_pool_baseline.log`: Valgrind leak report for pool test
- `massif_pool_baseline.out`: Massif memory profile for pool test
- `massif_ssl_investigation.out`: Massif memory profile for SSL investigation
- `massif_ssl_report.txt`: Human-readable SSL memory profile (if `ms_print` is available)
- `dynamic_analysis.log`: Main log for run_dynamic_analysis.sh (GDB/SSL trace summary)
- `dynamic_analysis_summary.log`: High-level summary of dynamic analysis results
Comment on lines +126 to +127
Copy link

Copilot AI Mar 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

README documents dynamic_analysis.log / dynamic_analysis_summary.log outputs, but the script currently produces timestamped files under dynamic_analysis_results/ with different names. Align the README’s “Log Files & Outputs” section with the actual filenames produced (or change the script to match the documented names).

Suggested change
- `dynamic_analysis.log`: Main log for run_dynamic_analysis.sh (GDB/SSL trace summary)
- `dynamic_analysis_summary.log`: High-level summary of dynamic analysis results
- `dynamic_analysis_results/`: Directory containing logs produced by `run_dynamic_analysis.sh`. Each run creates timestamped files, for example:
- `dynamic_analysis_YYYYMMDD_HHMMSS.log`: Main log for `run_dynamic_analysis.sh` (GDB/SSL trace summary)
- `dynamic_analysis_summary_YYYYMMDD_HHMMSS.log`: High-level summary of dynamic analysis results

Copilot uses AI. Check for mistakes.
## run_dynamic_analysis.sh

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.

**Usage:**

```bash
./run_dynamic_analysis.sh # Run full dynamic analysis suite
./run_dynamic_analysis.sh --help # Show all options and usage
```

**Features:**
- Automated GDB tracing of SSL/OpenSSL allocation and cleanup functions
- Per-iteration and summary logging
- Timeout and iteration controls (via environment variables)
- Correlates memory growth with SSL connection pool operations
- Produces logs for management and engineering review

See the script header or run with `--help` for full details and advanced options.


## Requirements

- Linux environment (WSL2 supported)
- libcurl development headers
- Valgrind (for valgrind-integrated tests)
- Internet connection (tests use httpbin.org)

## Troubleshooting & Tips

- If you see memory growth, check the logs and Valgrind output for SSL/OpenSSL or curl-related leaks.
- Use environment variables to tune pool size and iteration count for your environment.
- For deep SSL/OpenSSL memory analysis, use the `--valgrind-ssl` option and review `massif_ssl_report.txt`.

For full CLI usage and test descriptions, run:

```bash
./memory_verifier --help
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
=== 1. GDB Call Stack Analysis ===
Running GDB dynamic analysis using gdb_batch_script.gdb...
Setting 30-second timeout with 50 iterations...
Setting T2_TEST_ITERATIONS=50 for this test...
✅ GDB analysis completed normally
=== Dynamic Analysis Summary ===
Analysis completed at: Wed Mar 11 01:01:09 PM EDT 2026

📁 Generated Files:
-rw-r--r-- 1 root root 336 Mar 11 13:01 dynamic_analysis_results/dynamic_ssl_20260311_130038_analysis.log
-rw-r--r-- 1 root root 492202 Mar 11 13:01 dynamic_analysis_results/dynamic_ssl_20260311_130038_gdb_trace.log

📊 Quick Analysis:
=== ALLOCATION ANALYSIS ===
EVP_CIPHER_fetch calls: 2
CRYPTO allocation calls: 6456
RAND_get0_primary calls: 2
=== DEALLOCATION ANALYSIS ===
CRYPTO_free calls: 2242
EVP_CIPHER_free calls: 2
SSL_CTX_free calls: 2
=== MEMORY LEAK ASSESSMENT ===
⚠️ POTENTIAL LEAK: 4212 more allocations than deallocations

Loading
Loading