The best thing to do is add an internal reference instead of referencing the parent. e.g. if (pShader != NULL) { IWineD3DVertexShader_AddRef(pShader); } if (oldShader != NULL) { IWineD3DVertexShader_Release(oldShader); }
Is that reference really needed?