Commit c2d7bc3f2831dfbe9406b0858dbae9384247467d

Stefan Sperling 2021-08-31T19:11:16

remove superfluous strdup(3) from parse.y files; Patch by Martin Vahlensieck

diff --git a/gotweb/parse.y b/gotweb/parse.y
index 2d9864e..91c2400 100644
--- a/gotweb/parse.y
+++ b/gotweb/parse.y
@@ -118,71 +118,29 @@ boolean		: STRING {
 		}
 		;
 main		: GOT_REPOS_PATH STRING {
-			gw_conf->got_repos_path = strdup($2);
-			if (gw_conf->got_repos_path == NULL) {
-				free($2);
-				yyerror("strdup");
-				YYERROR;
-			}
-			free($2);
+			gw_conf->got_repos_path = $2;
 		}
 		| GOT_WWW_PATH STRING {
-			gw_conf->got_www_path = strdup($2);
-			if (gw_conf->got_www_path == NULL) {
-				free($2);
-				yyerror("strdup");
-				YYERROR;
-			}
-			free($2);
+			gw_conf->got_www_path = $2;
 		}
 		| GOT_MAX_REPOS NUMBER {
 			if ($2 > 0)
 				gw_conf->got_max_repos = $2;
 		}
 		| GOT_SITE_NAME STRING {
-			gw_conf->got_site_name = strdup($2);
-			if (gw_conf->got_site_name == NULL) {
-				free($2);
-				yyerror("strdup");
-				YYERROR;
-			}
-			free($2);
+			gw_conf->got_site_name = $2;
 		}
 		| GOT_SITE_OWNER STRING {
-			gw_conf->got_site_owner = strdup($2);
-			if (gw_conf->got_site_owner == NULL) {
-				free($2);
-				yyerror("strdup");
-				YYERROR;
-			}
-			free($2);
+			gw_conf->got_site_owner = $2;
 		}
 		| GOT_SITE_LINK STRING {
-			gw_conf->got_site_link = strdup($2);
-			if (gw_conf->got_site_link == NULL) {
-				free($2);
-				yyerror("strdup");
-				YYERROR;
-			}
-			free($2);
+			gw_conf->got_site_link = $2;
 		}
 		| GOT_LOGO STRING {
-			gw_conf->got_logo = strdup($2);
-			if (gw_conf->got_logo== NULL) {
-				free($2);
-				yyerror("strdup");
-				YYERROR;
-			}
-			free($2);
+			gw_conf->got_logo = $2;
 		}
 		| GOT_LOGO_URL STRING {
-			gw_conf->got_logo_url = strdup($2);
-			if (gw_conf->got_logo_url== NULL) {
-				free($2);
-				yyerror("strdup");
-				YYERROR;
-			}
-			free($2);
+			gw_conf->got_logo_url = $2;
 		}
 		| GOT_SHOW_SITE_OWNER boolean {
 			gw_conf->got_show_site_owner = $2;
@@ -232,9 +190,8 @@ yyerror(const char *fmt, ...)
 		gerror = got_error_from_errno("asprintf");
 		return(0);
 	}
-	gerror = got_error_msg(GOT_ERR_PARSE_CONFIG, strdup(err));
+	gerror = got_error_msg(GOT_ERR_PARSE_CONFIG, err);
 	free(msg);
-	free(err);
 	return(0);
 }
 
diff --git a/libexec/got-read-gotconfig/parse.y b/libexec/got-read-gotconfig/parse.y
index f1fe635..13c0d95 100644
--- a/libexec/got-read-gotconfig/parse.y
+++ b/libexec/got-read-gotconfig/parse.y
@@ -192,31 +192,13 @@ remoteopts2	: remoteopts2 remoteopts1 nl
 	   	| remoteopts1 optnl
 		;
 remoteopts1	: REPOSITORY STRING {
-	   		remote->repository = strdup($2);
-			if (remote->repository == NULL) {
-				free($2);
-				yyerror("strdup");
-				YYERROR;
-			}
-			free($2);
+	   		remote->repository = $2;
 	   	}
 	   	| SERVER STRING {
-	   		remote->server = strdup($2);
-			if (remote->server == NULL) {
-				free($2);
-				yyerror("strdup");
-				YYERROR;
-			}
-			free($2);
+	   		remote->server = $2;
 		}
 		| PROTOCOL STRING {
-	   		remote->protocol = strdup($2);
-			if (remote->protocol == NULL) {
-				free($2);
-				yyerror("strdup");
-				YYERROR;
-			}
-			free($2);
+	   		remote->protocol = $2;
 		}
 		| MIRROR_REFERENCES boolean {
 			remote->mirror_references = $2;
@@ -267,31 +249,13 @@ fetchopts2	: fetchopts2 fetchopts1 nl
 	   	| fetchopts1 optnl
 		;
 fetchopts1	: REPOSITORY STRING {
-	   		remote->fetch_config->repository = strdup($2);
-			if (remote->fetch_config->repository == NULL) {
-				free($2);
-				yyerror("strdup");
-				YYERROR;
-			}
-			free($2);
+	   		remote->fetch_config->repository = $2;
 	   	}
 	   	| SERVER STRING {
-	   		remote->fetch_config->server = strdup($2);
-			if (remote->fetch_config->server == NULL) {
-				free($2);
-				yyerror("strdup");
-				YYERROR;
-			}
-			free($2);
+	   		remote->fetch_config->server = $2;
 		}
 		| PROTOCOL STRING {
-	   		remote->fetch_config->protocol = strdup($2);
-			if (remote->fetch_config->protocol == NULL) {
-				free($2);
-				yyerror("strdup");
-				YYERROR;
-			}
-			free($2);
+	   		remote->fetch_config->protocol = $2;
 		}
 		| PORT portplain {
 			remote->fetch_config->port = $2;
@@ -307,31 +271,13 @@ sendopts2	: sendopts2 sendopts1 nl
 	   	| sendopts1 optnl
 		;
 sendopts1	: REPOSITORY STRING {
-	   		remote->send_config->repository = strdup($2);
-			if (remote->send_config->repository == NULL) {
-				free($2);
-				yyerror("strdup");
-				YYERROR;
-			}
-			free($2);
+	   		remote->send_config->repository = $2;
 	   	}
 	   	| SERVER STRING {
-	   		remote->send_config->server = strdup($2);
-			if (remote->send_config->server == NULL) {
-				free($2);
-				yyerror("strdup");
-				YYERROR;
-			}
-			free($2);
+	   		remote->send_config->server = $2;
 		}
 		| PROTOCOL STRING {
-	   		remote->send_config->protocol = strdup($2);
-			if (remote->send_config->protocol == NULL) {
-				free($2);
-				yyerror("strdup");
-				YYERROR;
-			}
-			free($2);
+	   		remote->send_config->protocol = $2;
 		}
 		| PORT portplain {
 			remote->send_config->port = $2;
@@ -349,26 +295,14 @@ remote		: REMOTE STRING {
 				yyerror("%s", error->msg);
 				YYERROR;
 			}
-			remote->name = strdup($2);
-			if (remote->name == NULL) {
-				free($2);
-				yyerror("strdup");
-				YYERROR;
-			}
-			free($2);
+			remote->name = $2;
 		} '{' optnl remoteopts2 '}' {
 			TAILQ_INSERT_TAIL(&gotconfig.remotes, remote, entry);
 			gotconfig.nremotes++;
 		}
 		;
 author		: AUTHOR STRING {
-	   		gotconfig.author = strdup($2);
-			if (gotconfig.author == NULL) {
-				free($2);
-				yyerror("strdup");
-				YYERROR;
-			}
-			free($2);
+	   		gotconfig.author = $2;
 		}
 		;
 optnl		: '\n' optnl
@@ -404,9 +338,8 @@ yyerror(const char *fmt, ...)
 		gerror = got_error_from_errno("asprintf");
 		return(0);
 	}
-	gerror = got_error_msg(GOT_ERR_PARSE_CONFIG, strdup(err));
+	gerror = got_error_msg(GOT_ERR_PARSE_CONFIG, err);
 	free(msg);
-	free(err);
 	return(0);
 }
 int