diag: dci: Safeguard to prevent Integer Underflow and Memory Leak