We have to use the factory that created the SurfaceImageSource; We should not create a new factory. So our will have code like this:
ID2D1Factory *pFactory=nullptr;
d2dDevice->GetFactory(&pFactory);
ID2D1GeometrySink *pSink = NULL;
ID2D1PathGeometry *pPathGeometry=NULL;
// Create a path geometry.
HRESULT hr = pFactory->CreatePathGeometry(&pPathGeometry);
Finally it solved my problem.