tensor product of non free modules which is free 
Does anyone have an example of a commutative ring $R$ (with a unit) and two non-free $R$-modules $S$ and $T$ such that $S \otimes_R T$ is a non-zero free module?

I only know of classical examples like $\mathbb Q \otimes_\mathbb Z \mathbb Z/n\mathbb Z \cong 0$ and was asked by one of our students of a non-zero example (which I couldn't think of in reasonable time).
I am not even sure, if this exists for commutative rings but it is clear that such $S$ and $T$ don't both contain free sub modules, in particular for $R$ a PID and $S$ and $T$ finitely generated such a thing should not exists (since we have a decomposition into free sub modules and torsion sub modules).
A similar question can be found here (with $R=\mathbb Z$) and the first link in it contains practically my question (without answers).
 A: Here's an example.  Let $A$ and $B$ be two nonzero commutative rings and $R=A\times B$.  We can consider $A$ and $B$ as $R$-modules, and they satisfy $A\otimes B\cong 0$ and $A\oplus B\cong R$.  Taking $S=A\oplus R$ and $T=B\oplus R$, we thus see that $$S\otimes T\cong A\oplus B\oplus R\cong R^2$$ is free but $S$ and $T$ are not free.  More generally, $(A^i\oplus B^j)\otimes(A^k\oplus B^l)\cong A^{ik}\oplus B^{jl}$ is free iff $ik=jl$, but the factors are not free unless $i=j$ and $k=l$.
A: In general if we have an invertible $R$-module $M$, then the natural map $M \otimes_R M^\vee \to R$ is an isomorphism, where $M^\vee = \operatorname{Hom}_R(M,R)$ is its dual module. If $R$ is a Dedekind domain then every fractional ideal is an invertible $R$-module, and if $R$ has nontrivial class group, then any nonprincipal fractional ideal fulfills your requirements.
For an explicit example, take $R = \mathbb{Z}[\sqrt{-5}]$ and $I = (2, 1 + \sqrt{-5})$. Then $I \otimes_R I^\vee \cong R$, but since $I$ is nonprincipal, then it is not free. Since the class group of $\mathbb{Z}[\sqrt{-5}]$ has order $2$, then it turns out that $I^\vee \cong I$, so it is also not free.
For more examples and results on invertible modules, see $\S11.3$ of Eisenbud's commutative algebra book.
