@@ -362,21 +362,20 @@ static int parse_config(const char *var, const char *value, void *data)
362
362
}
363
363
364
364
static int gitmodule_sha1_from_commit (const unsigned char * commit_sha1 ,
365
- unsigned char * gitmodules_sha1 )
365
+ unsigned char * gitmodules_sha1 ,
366
+ struct strbuf * rev )
366
367
{
367
- struct strbuf rev = STRBUF_INIT ;
368
368
int ret = 0 ;
369
369
370
370
if (is_null_sha1 (commit_sha1 )) {
371
371
hashcpy (gitmodules_sha1 , null_sha1 );
372
372
return 1 ;
373
373
}
374
374
375
- strbuf_addf (& rev , "%s:.gitmodules" , sha1_to_hex (commit_sha1 ));
376
- if (get_sha1 (rev . buf , gitmodules_sha1 ) >= 0 )
375
+ strbuf_addf (rev , "%s:.gitmodules" , sha1_to_hex (commit_sha1 ));
376
+ if (get_sha1 (rev -> buf , gitmodules_sha1 ) >= 0 )
377
377
ret = 1 ;
378
378
379
- strbuf_release (& rev );
380
379
return ret ;
381
380
}
382
381
@@ -390,7 +389,7 @@ static const struct submodule *config_from(struct submodule_cache *cache,
390
389
{
391
390
struct strbuf rev = STRBUF_INIT ;
392
391
unsigned long config_size ;
393
- char * config ;
392
+ char * config = NULL ;
394
393
unsigned char sha1 [20 ];
395
394
enum object_type type ;
396
395
const struct submodule * submodule = NULL ;
@@ -411,8 +410,8 @@ static const struct submodule *config_from(struct submodule_cache *cache,
411
410
return entry -> config ;
412
411
}
413
412
414
- if (!gitmodule_sha1_from_commit (commit_sha1 , sha1 ))
415
- return NULL ;
413
+ if (!gitmodule_sha1_from_commit (commit_sha1 , sha1 , & rev ))
414
+ goto out ;
416
415
417
416
switch (lookup_type ) {
418
417
case lookup_name :
@@ -423,16 +422,11 @@ static const struct submodule *config_from(struct submodule_cache *cache,
423
422
break ;
424
423
}
425
424
if (submodule )
426
- return submodule ;
425
+ goto out ;
427
426
428
427
config = read_sha1_file (sha1 , & type , & config_size );
429
- if (!config )
430
- return NULL ;
431
-
432
- if (type != OBJ_BLOB ) {
433
- free (config );
434
- return NULL ;
435
- }
428
+ if (!config || type != OBJ_BLOB )
429
+ goto out ;
436
430
437
431
/* fill the submodule config into the cache */
438
432
parameter .cache = cache ;
@@ -441,6 +435,7 @@ static const struct submodule *config_from(struct submodule_cache *cache,
441
435
parameter .overwrite = 0 ;
442
436
git_config_from_mem (parse_config , "submodule-blob" , rev .buf ,
443
437
config , config_size , & parameter );
438
+ strbuf_release (& rev );
444
439
free (config );
445
440
446
441
switch (lookup_type ) {
@@ -451,6 +446,11 @@ static const struct submodule *config_from(struct submodule_cache *cache,
451
446
default :
452
447
return NULL ;
453
448
}
449
+
450
+ out :
451
+ strbuf_release (& rev );
452
+ free (config );
453
+ return submodule ;
454
454
}
455
455
456
456
static const struct submodule * config_from_path (struct submodule_cache * cache ,
0 commit comments