@@ -338,7 +338,7 @@ static int curl(char *op, const char *path, const char *uri)
338338 char * argv [] = {
339339 "curl" , "-L" , op , NULL , NULL , NULL , NULL , NULL ,
340340 };
341- int err ;
341+ int err = 1 ;
342342
343343 argv [3 ] = strdup (path );
344344 argv [4 ] = strdup (uri );
@@ -390,7 +390,7 @@ static int cp(const char *srcpath, const char *dstpath)
390390 char * argv [] = {
391391 "cp" , NULL , NULL , NULL ,
392392 };
393- int err ;
393+ int err = 1 ;
394394
395395 argv [1 ] = strdup (srcpath );
396396 argv [2 ] = strdup (dstpath );
@@ -442,13 +442,20 @@ static int get(const char *src, const struct infix_ds *ds, const char *path)
442442
443443static int resolve_src (const char * * src , const struct infix_ds * * ds , char * * path , bool * rm )
444444{
445+ int tmpfd ;
446+
445447 * src = infix_ds (* src , ds );
446448
447449 if (* ds || is_uri (* src )) {
448- * path = tempnam ( NULL , NULL );
450+ * path = strdup ( "/tmp/copy-XXXXXX" );
449451 if (!* path )
450452 return 1 ;
451453
454+ tmpfd = mkstemp (* path );
455+ if (tmpfd < 0 )
456+ return 1 ;
457+
458+ close (tmpfd );
452459 * rm = true;
453460 return 0 ;
454461 } else {
@@ -477,7 +484,7 @@ static int resolve_dst(const char **dst, const struct infix_ds **ds, char **path
477484 if (!(* ds )-> path )
478485 return 0 ;
479486
480- * path = ( * ds )-> path ;
487+ * path = strdup (( * ds )-> path ) ;
481488 } else if (is_uri (* dst )) {
482489 return 0 ;
483490 } else {
@@ -499,8 +506,8 @@ static int resolve_dst(const char **dst, const struct infix_ds **ds, char **path
499506
500507static int copy (const char * src , const char * dst )
501508{
509+ char * srcpath = NULL , * dstpath = NULL ;
502510 const struct infix_ds * srcds , * dstds ;
503- char * srcpath , * dstpath ;
504511 bool rmsrc = false;
505512 mode_t oldmask ;
506513 int err = 1 ;
@@ -534,6 +541,9 @@ static int copy(const char *src, const char *dst)
534541 if (rmsrc )
535542 rmtmp (srcpath );
536543
544+ free (dstpath );
545+ free (srcpath );
546+
537547 sync ();
538548 umask (oldmask );
539549 return err ;
0 commit comments