Raymond Toy pushed to branch issue-130-file-author-in-c at cmucl / cmucl

Commits:

1 changed file:

Changes:

  • src/lisp/os-common.c
    ... ... @@ -730,7 +730,7 @@ os_file_author(const char *path)
    730 730
     {
    
    731 731
         struct stat sb;
    
    732 732
         char initial[1024];
    
    733
    -    char *buffer, *newbuffer;
    
    733
    +    char *buffer, *obuffer;
    
    734 734
         size_t size;
    
    735 735
         struct passwd pwd;
    
    736 736
         struct passwd *ppwd;
    
    ... ... @@ -742,6 +742,7 @@ os_file_author(const char *path)
    742 742
     
    
    743 743
         result = NULL;
    
    744 744
         buffer = initial;
    
    745
    +    obuffer = NULL;
    
    745 746
         size = sizeof(initial) / sizeof(initial[0]);
    
    746 747
     
    
    747 748
         /*
    
    ... ... @@ -757,11 +758,10 @@ os_file_author(const char *path)
    757 758
               case ERANGE:
    
    758 759
                   /* Buffer is too small, double its size and try again */
    
    759 760
                   size *= 2;
    
    760
    -              if ((newbuffer = realloc((buffer == initial) ? NULL : buffer,
    
    761
    -                                       size)) == NULL) {
    
    761
    +              obuffer = (buffer == initial) ? NULL : buffer;
    
    762
    +              if ((buffer = realloc(obuffer, size)) == NULL) {
    
    762 763
                       goto exit;
    
    763 764
                   }
    
    764
    -              buffer = newbuffer;
    
    765 765
                   continue;
    
    766 766
               default:
    
    767 767
                   /* All other errors */
    
    ... ... @@ -769,9 +769,7 @@ os_file_author(const char *path)
    769 769
             }
    
    770 770
         }
    
    771 771
     exit:
    
    772
    -    if (buffer != initial) {
    
    773
    -        free(buffer);
    
    774
    -    }
    
    772
    +    free(obuffer);
    
    775 773
         
    
    776 774
         return result;
    
    777 775
     }