This holds for integral domains $R$ and finitely generated $R$-modules. If we put $A = M_1, B = M_2,$ and $C = M_3$, then the given short exact sequence is isomorphic to the following short exact sequence:
$$
0 \to M_1 \to M_2 \to M_2/M_1 \to 0.
$$
If $r_1 = \operatorname{rank}M_1$, $r_2 = \operatorname{rank} M_2$, and $r_3 = \operatorname{rank} M_3 = \operatorname{rank} M_2/M_1$, then let $u_1,\dots,u_{r_1}$ be linearly independent in $M_1$ and $\bar v_1,\dots,\bar v_{r_3}$ be linearly independent in $M_2/M_1$. Then, if
$$
a_1u_1 + \dotsb + a_{r_1}u_{r_1} + b_1v_1 + \dotsb + b_{r_3}v_{r_3} = 0,
$$
in $M$, then reducing this equation modulo $M_1$ gives
$$
b_1\bar v_1 + \dotsb + b_{r_3}\bar v_{r_3} = \bar 0\quad\text{in $M_2/M_1$},
$$
so $b_1 = \dots = b_{r_3} = 0$ by linear independence of these elements, and thus $a_1 = \dotsb = a_{r_1} = 0$ by linear independence of the $u_i$. Hence $\operatorname{rank} M_2 \geqslant r_1 + r_3$.
Suppose that $w_1,\dots,w_s$ are linearly independent in $M_2$ with $s > r_1 + r_3$. Now (exercise) there is a free submodule $N/M_1\subset M_2/M_1$ with $R^{r_3}\cong N/M_1$ such that $(M_2/M_1)\big/(N/M_1)\cong M_2/N$ is a torsion module.
Since $N/M_1$ is free of rank $r_3$, there is $0\leqslant n\leqslant r_3$ such that $n$ of the $\bar w_1,\dots,\bar w_s$ are nonzero in $M_2/M_1$ and belong to $N/M_1$. After reindexing, assume that $\bar w_1,\dots,\bar w_{s-n}$ are either zero in $M_2/M_1$ or belong to $(M_2/M_1)\smallsetminus(N/M_1)$. Since $0\leqslant n\leqslant r_3$, we have $s-n\geqslant s-r_3 > r_1$. Removing the elements in the list that are equal to $\bar 0$ in $M_2/M_1$ and reindexing, we obtain a new list $\bar w_1,\dots,\bar w_j$ with $0\leqslant j \leqslant s-n$ and such that each $\bar w_j$ is nonzero in $M_2/M_1$, and even nonzero in $T:=(M_2/M_1)\big/(N/M_1)$. Since $T$ is a torsion module, for each $j$, there is an $x_j\in R\smallsetminus\{0\}$ such that $x_j\bar w_j = \bar 0 \bmod N/M_1$ in $T$. Thus, we end up with $s-n > r_1$ elements:
$$x_1\bar w_1=\dots=x_j\bar w_j=\bar w_{j+1}=\dots=\bar w_{j+(s-n-j)}=\bar w_{s-n}=\bar 0\quad\text{in $N/M_1$}.
$$
Thus, we have $x_1w_1,\dots,x_jw_j,w_{j+1},\dots,w_{s-n}$ belong to $M_1$, and it is easy to see that these elements are linearly independent in $M_1$ since $R$ is an integral domain and the elements $w_1,\dots,w_j,w_{j+1},\dots,w_{s-n}$ are linearly independent by assumption. But the rank of $M_1$ is $r_1 < s-n$, so this is a contradiction. Consequently, $\operatorname{rank} M_2 \leqslant r_1 + r_3$, so
$$
\operatorname{rank} M_2 = r_1 + r_3 = \operatorname{rank} M_1 + \operatorname{rank} M_3,
$$
as desired.