TITLE: tensor product of non free modules which is free
QUESTION [6 upvotes]: 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).

REPLY [4 votes]: 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.