@@ -192,15 +192,15 @@ static int canonicalize_url(git_buf *out, const char *in)
192192static int create_internal (git_remote * * out , git_repository * repo , const char * name , const char * url , const char * fetch )
193193{
194194 git_remote * remote ;
195- git_config * config = NULL ;
195+ git_config * config_ro = NULL , * config_rw ;
196196 git_buf canonical_url = GIT_BUF_INIT ;
197197 git_buf var = GIT_BUF_INIT ;
198198 int error = -1 ;
199199
200200 /* name is optional */
201201 assert (out && repo && url );
202202
203- if ((error = git_repository_config__weakptr ( & config , repo )) < 0 )
203+ if ((error = git_repository_config_snapshot ( & config_ro , repo )) < 0 )
204204 return error ;
205205
206206 remote = git__calloc (1 , sizeof (git_remote ));
@@ -212,7 +212,8 @@ static int create_internal(git_remote **out, git_repository *repo, const char *n
212212 (error = canonicalize_url (& canonical_url , url )) < 0 )
213213 goto on_error ;
214214
215- remote -> url = apply_insteadof (repo -> _config , canonical_url .ptr , GIT_DIRECTION_FETCH );
215+ remote -> url = apply_insteadof (config_ro , canonical_url .ptr , GIT_DIRECTION_FETCH );
216+ GITERR_CHECK_ALLOC (remote -> url );
216217
217218 if (name != NULL ) {
218219 remote -> name = git__strdup (name );
@@ -221,7 +222,8 @@ static int create_internal(git_remote **out, git_repository *repo, const char *n
221222 if ((error = git_buf_printf (& var , CONFIG_URL_FMT , name )) < 0 )
222223 goto on_error ;
223224
224- if ((error = git_config_set_string (config , var .ptr , canonical_url .ptr )) < 0 )
225+ if ((error = git_repository_config__weakptr (& config_rw , repo )) < 0 ||
226+ (error = git_config_set_string (config_rw , var .ptr , canonical_url .ptr )) < 0 )
225227 goto on_error ;
226228 }
227229
@@ -233,10 +235,7 @@ static int create_internal(git_remote **out, git_repository *repo, const char *n
233235 if (name && (error = write_add_refspec (repo , name , fetch , true)) < 0 )
234236 goto on_error ;
235237
236- if ((error = git_repository_config_snapshot (& config , repo )) < 0 )
237- goto on_error ;
238-
239- if ((error = lookup_remote_prune_config (remote , config , name )) < 0 )
238+ if ((error = lookup_remote_prune_config (remote , config_ro , name )) < 0 )
240239 goto on_error ;
241240
242241 /* Move the data over to where the matching functions can find them */
@@ -260,6 +259,7 @@ static int create_internal(git_remote **out, git_repository *repo, const char *n
260259 if (error )
261260 git_remote_free (remote );
262261
262+ git_config_free (config_ro );
263263 git_buf_free (& canonical_url );
264264 git_buf_free (& var );
265265 return error ;
0 commit comments