if (v.val.p) { wrapper = new DConnectInstance(peer, iinfo, (nsISupports *) v.val.p); if (!wrapper) return NS_ERROR_OUT_OF_MEMORY;
nsCOMPtr<nsIInterfaceInfo> iinfo; rv = gDConnect->GetInterfaceInfo(iid, getter_AddRefs(iinfo)); if (NS_FAILED(rv)) return rv;  DConnectInstance *wrapper = nsnull;  wrapper = new DConnectInstance(peer, iinfo, obj); if (!wrapper) return NS_ERROR_OUT_OF_MEMORY;  if (!wrappers.AppendElement(wrapper)) { delete wrapper; return NS_ERROR_OUT_OF_MEMORY; }  rv = gDConnect->StoreInstance(wrapper); if (NS_FAILED(rv)) { wrappers.RemoveElement(wrapper); delete wrapper; return rv; }    PtrBits bits = ((PtrBits) wrapper) | 0x1; writer.PutBytes(&bits, sizeof(bits)); } NS_IF_RELEASE(stub);
SerializeInterfaceParam(ipcMessageWriter &writer,                        PRUint32 peer, const nsID &iid,                        const nsXPTType &type, const nsXPTCMiniVariant &v,                        nsVoidArray &wrappers){  // we create an instance wrapper, and assume that the other side will send a  // RELEASE message when it no longer needs the instance wrapper.  that will  // usually happen after the call returns.  //  // XXX a lazy scheme might be better, but for now simplicity wins.  nsCOMPtr<nsIInterfaceInfo> iinfo;  nsresult rv = gDConnect->GetInterfaceInfo(iid, getter_AddRefs(iinfo));  if (NS_FAILED(rv))    return rv;  DConnectInstance *wrapper = nsnull;  if (v.val.p)  {    wrapper = new DConnectInstance(peer, iinfo, (nsISupports *) v.val.p);    if (!wrapper)      return NS_ERROR_OUT_OF_MEMORY;  }  if (!wrappers.AppendElement(wrapper))    return NS_ERROR_OUT_OF_MEMORY;  rv = gDConnect->StoreInstance(wrapper);  if (NS_FAILED(rv))    return rv;  // send address of the instance wrapper  writer.PutBytes(&wrapper, sizeof(wrapper));  return NS_OK;}