Evaluate $$\int_{0}^{2\pi}\frac{d \theta}{1+2p\cos \theta+p^2}$$ where $0<|p|<1$
$$\int_{0}^{2\pi}\frac{d \theta}{1+2p\cos \theta+p^2}=\frac{1}{i}\int_{|z|=1}\frac{d z}{z(1+pz+\frac{p}{z}+p^2)}=\frac{1}{i}\int_{|z|=1}\frac{d z}{z+pz^2+p+zp^2}=\\ =\frac{1}{i}\int_{|z|=1}\frac{d z}{pz^2+(p^2+1)z+p}$$
$pz^2+(p^2+1)z+p=0$ Then $z_1=0,z_2=-p$
$Res(f,0)=lim_{z\to 0}\frac{z}{z(z+p)}=\frac{1}{p}$
$Res(f,-p)=lim_{z\to -p}\frac{(z+p)}{z(z+p)}=-\frac{1}{p}$
So it is $\frac{1}{i}2\pi i (\frac{1}{p}-\frac{1}{p})=0$
But the answer is $\frac{2\pi }{1-p^2}$
Where did it went wrong?