This paper provides a methodology for valuing a credit default swap (CDS) with considering a counterparty default risk. Using a structural framework, we study the correlation of the reference entity and the counterparty through the joint distribution of them. The default event discussed in our model is associated to whether the minimum value of the companies in stochastic processes has reached their thresholds (default barriers). The joint probability of minimums of correlated Brownian motions solves the backward Kolmogorov equation, which is a two dimensional partial differential equation. A closed pricing formula is obtained. Numerical methodology, parameter analysis and calculation examples are implemented.