diff --git a/res/res_musiconhold.c b/res/res_musiconhold.c
index 01920e087547bdccbb42ba9302a26394063b1a59..c1ab05dac4970436949b95f3af8b75c15985c3e6 100644
--- a/res/res_musiconhold.c
+++ b/res/res_musiconhold.c
@@ -1072,7 +1072,9 @@ static int moh_register(struct mohclass *moh, int reload, int unref)
 		if (!mohclass->delete) {
  			ast_log(LOG_WARNING, "Music on Hold class '%s' already exists\n", moh->name);
 			mohclass = mohclass_unref(mohclass, "unreffing mohclass we just found by name");
-			moh = mohclass_unref(moh, "unreffing potential new moh class (it is a duplicate)");
+			if (unref) {
+				moh = mohclass_unref(moh, "unreffing potential new moh class (it is a duplicate)");
+			}
 			return -1;
 		}
 		mohclass = mohclass_unref(mohclass, "Unreffing mohclass we just found by name");