misc: Replace the idiom for replacing a string with a function call

Remove a lot of code in favor of a new function that is freeing
the old string and copying the new one. I should have gotten the
context and the strings right.
diff --git a/openbsc/src/mgcp/mgcp_vty.c b/openbsc/src/mgcp/mgcp_vty.c
index a9845a1..d78b8c7 100644
--- a/openbsc/src/mgcp/mgcp_vty.c
+++ b/openbsc/src/mgcp/mgcp_vty.c
@@ -127,9 +127,7 @@
       "local ip A.B.C.D",
       "Set the IP to be used in SDP records")
 {
-	if (g_cfg->local_ip)
-		talloc_free(g_cfg->local_ip);
-	g_cfg->local_ip = talloc_strdup(g_cfg, argv[0]);
+	bsc_replace_string(g_cfg, &g_cfg->local_ip, argv[0]);
 	return CMD_SUCCESS;
 }
 
@@ -138,9 +136,7 @@
       "bts ip A.B.C.D",
       "Set the IP of the BTS for RTP forwarding")
 {
-	if (g_cfg->bts_ip)
-		talloc_free(g_cfg->bts_ip);
-	g_cfg->bts_ip = talloc_strdup(g_cfg, argv[0]);
+	bsc_replace_string(g_cfg, &g_cfg->bts_ip, argv[0]);
 	inet_aton(g_cfg->bts_ip, &g_cfg->bts_in);
 	return CMD_SUCCESS;
 }
@@ -150,9 +146,7 @@
       "bind ip A.B.C.D",
       "Bind the MGCP to this local addr")
 {
-	if (g_cfg->source_addr)
-		talloc_free(g_cfg->source_addr);
-	g_cfg->source_addr = talloc_strdup(g_cfg, argv[0]);
+	bsc_replace_string(g_cfg, &g_cfg->source_addr, argv[0]);
 	return CMD_SUCCESS;
 }
 
@@ -281,9 +275,7 @@
       "sdp audio payload name NAME",
       "Set the audio name to use")
 {
-	if (g_cfg->audio_name)
-		talloc_free(g_cfg->audio_name);
-	g_cfg->audio_name = talloc_strdup(g_cfg, argv[0]);
+	bsc_replace_string(g_cfg, &g_cfg->audio_name, argv[0]);
 	return CMD_SUCCESS;
 }
 
@@ -311,9 +303,7 @@
       "call agent ip IP",
       "Set the address of the call agent.")
 {
-	if (g_cfg->call_agent_addr)
-		talloc_free(g_cfg->call_agent_addr);
-	g_cfg->call_agent_addr = talloc_strdup(g_cfg, argv[0]);
+	bsc_replace_string(g_cfg, &g_cfg->call_agent_addr, argv[0]);
 	return CMD_SUCCESS;
 }
 
@@ -323,9 +313,7 @@
       "Use a MGW to detranscoder RTP\n"
       "The IP address of the MGW")
 {
-	if (g_cfg->transcoder_ip)
-		talloc_free(g_cfg->transcoder_ip);
-	g_cfg->transcoder_ip = talloc_strdup(g_cfg, argv[0]);
+	bsc_replace_string(g_cfg, &g_cfg->transcoder_ip, argv[0]);
 	inet_aton(g_cfg->transcoder_ip, &g_cfg->transcoder_in);
 
 	return CMD_SUCCESS;