Presumably you're thinking that when C and D annihilate they turn into massless photons so their gravitational field must disappear, hence the problem of what happens to the gravitational energy that A and B acquired in moving away from C and D.
The answer is that the gravitational field of C and D is not generated by their mass, but by their energy density. Energy gravitates in exactly the same way that mass does. The equivalence between the two is just the formula we've all see a hundred times: $E = mc^2$. Life is actually a bit more complicated than this, because the spacetime curvature that creates gravity is actually proportional to an object called the stress-energy tensor. However the mass/energy density is usually the most important part of this object
So at the instant that C and D annihilate, the other two particles feel no change in the gravitational field and their gravitational potntial energy doesn't change. What happens next is more complicated because the photons created by the annihilation fly off at the speed of light so of course the gravitational field felt by A and B changes. Calculating the gravitational field created by a photon isn't a trivial business, though Googling should find you papers on the subject.