@@ -548,27 +548,32 @@ int file_getlk(FAR struct file *filep, FAR struct flock *flock)
548
548
{
549
549
FAR struct file_lock_bucket_s * bucket ;
550
550
FAR struct file_lock_s * file_lock ;
551
- char path [ PATH_MAX ] ;
551
+ FAR char * path ;
552
552
int ret ;
553
553
554
554
/* We need to get the unique identifier (Path) via filep */
555
555
556
+ path = lib_get_pathbuffer ();
557
+ if (path == NULL )
558
+ {
559
+ return - ENOMEM ;
560
+ }
561
+
556
562
ret = file_lock_get_path (filep , path );
557
563
if (ret < 0 )
558
564
{
559
- return ret ;
565
+ goto out_free ;
560
566
}
561
567
562
568
/* Convert a flock to a posix lock */
563
569
564
570
ret = file_lock_normalize (filep , flock , flock );
565
571
if (ret < 0 )
566
572
{
567
- return ret ;
573
+ goto out_free ;
568
574
}
569
575
570
576
nxmutex_lock (& g_protect_lock );
571
-
572
577
bucket = file_lock_find_bucket (path );
573
578
if (bucket != NULL )
574
579
{
@@ -602,6 +607,8 @@ int file_getlk(FAR struct file *filep, FAR struct flock *flock)
602
607
flock -> l_len = flock -> l_end - flock -> l_start + 1 ;
603
608
}
604
609
610
+ out_free :
611
+ lib_put_pathbuffer (path );
605
612
return OK ;
606
613
}
607
614
@@ -626,24 +633,30 @@ int file_setlk(FAR struct file *filep, FAR struct flock *flock,
626
633
{
627
634
FAR struct file_lock_bucket_s * bucket ;
628
635
FAR struct file_lock_s * file_lock ;
636
+ FAR char * path ;
629
637
struct flock request ;
630
- char path [PATH_MAX ];
631
638
int ret ;
632
639
640
+ path = lib_get_pathbuffer ();
641
+ if (path == NULL )
642
+ {
643
+ return - ENOMEM ;
644
+ }
645
+
633
646
/* We need to get the unique identifier (Path) via filep */
634
647
635
648
ret = file_lock_get_path (filep , path );
636
649
if (ret < 0 )
637
650
{
638
- return ret ;
651
+ goto out_free ;
639
652
}
640
653
641
654
/* Convert a flock to a posix lock */
642
655
643
656
ret = file_lock_normalize (filep , flock , & request );
644
657
if (ret < 0 )
645
658
{
646
- return ret ;
659
+ goto out_free ;
647
660
}
648
661
649
662
request .l_pid = getpid ();
@@ -659,17 +672,17 @@ int file_setlk(FAR struct file *filep, FAR struct flock *flock,
659
672
660
673
if (request .l_type == F_UNLCK )
661
674
{
662
- nxmutex_unlock ( & g_protect_lock ) ;
663
- return OK ;
675
+ ret = OK ;
676
+ goto out_lock ;
664
677
}
665
678
666
679
/* It looks like we didn't find a bucket, let's go create one */
667
680
668
681
bucket = file_lock_create_bucket (path );
669
682
if (bucket == NULL )
670
683
{
671
- nxmutex_unlock ( & g_protect_lock ) ;
672
- return - ENOMEM ;
684
+ ret = - ENOMEM ;
685
+ goto out_lock ;
673
686
}
674
687
}
675
688
else if (request .l_type != F_UNLCK )
@@ -711,7 +724,10 @@ int file_setlk(FAR struct file *filep, FAR struct flock *flock,
711
724
712
725
out :
713
726
file_lock_delete_bucket (bucket , path );
727
+ out_lock :
714
728
nxmutex_unlock (& g_protect_lock );
729
+ out_free :
730
+ lib_put_pathbuffer (path );
715
731
return ret ;
716
732
}
717
733
@@ -731,26 +747,32 @@ void file_closelk(FAR struct file *filep)
731
747
FAR struct file_lock_bucket_s * bucket ;
732
748
FAR struct file_lock_s * file_lock ;
733
749
FAR struct file_lock_s * temp ;
734
- char path [ PATH_MAX ] ;
750
+ FAR char * path ;
735
751
bool deleted = false;
736
752
int ret ;
737
753
754
+ path = lib_get_pathbuffer ();
755
+ if (path == NULL )
756
+ {
757
+ return ;
758
+ }
759
+
738
760
ret = file_lock_get_path (filep , path );
739
761
if (ret < 0 )
740
762
{
741
763
/* It isn't an error if fs doesn't support F_GETPATH, so we just end
742
764
* it.
743
765
*/
744
766
745
- return ;
767
+ goto out ;
746
768
}
747
769
748
770
bucket = file_lock_find_bucket (path );
749
771
if (bucket == NULL )
750
772
{
751
773
/* There is no bucket here, so we don't need to free it. */
752
774
753
- return ;
775
+ goto out ;
754
776
}
755
777
756
778
nxmutex_lock (& g_protect_lock );
@@ -774,6 +796,8 @@ void file_closelk(FAR struct file *filep)
774
796
}
775
797
776
798
nxmutex_unlock (& g_protect_lock );
799
+ out :
800
+ lib_put_pathbuffer (path );
777
801
}
778
802
779
803
/****************************************************************************
0 commit comments