genversion: fix minor memory leak

This commit is contained in:
Sebastien Alaiwan 2022-07-04 11:08:37 +02:00
parent 0b97df3666
commit f94e4ae4b0

View file

@ -39,7 +39,7 @@ int main(int argc, char * argv[]) {
FILE * file;
int old_ver[4] = { -1, -1, -1, -1 };
int new_ver[4] = { -1, -1, -1, -1 };
char* old_rev = (char*)calloc(sizeof(char), 1024);
char old_rev[1024] {};
if ( argc != 3 )
return 1;
@ -62,9 +62,10 @@ int main(int argc, char * argv[]) {
}
file = fopen(".git/HEAD", "r");
char git_rev_buf[1024] {};
char *git_rev, *gitrevfile;
if ( file ) {
git_rev = (char*)calloc(sizeof(char), 1024);
git_rev = git_rev_buf;
if (fscanf(file, "ref: %s", git_rev) != 1 ) {
fscanf(file, "%s", git_rev);
}
@ -74,7 +75,7 @@ int main(int argc, char * argv[]) {
file = fopen(gitrevfile, "r");
free(gitrevfile);
if (file) {
git_rev = (char*)calloc(sizeof(char), 1024);
git_rev = git_rev_buf;
fscanf(file, "%s", git_rev);
fclose(file);
}