Let $R$ be a subring of an integral domain $S$, and suppose $R$ is a PID. Then it follows that if $r\in R$ is a gcd of $r_1$ and $r_2$ in $R$, where $r_1$ and $r_2$ are not both zero, then $r$ is a gcd of $r_1$ and $r_2$ in $S$.
What I would like to know why the same conclusion would fail if $R$ is only an UFD instead of a PID. I have been trying to think of counter-examples of R, like for instance, $\mathbb{Z}[X]$ and etc., but to no avail. Is there any counter-examples to disprove the statement when $R$ is an UFD but not a PID?