commit: cc596f2b8d5401b276ab47e825b9136985dea408
parent 10ac3aa5885337bf7a969bf8bfca24f9dcd5428d
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date: Wed, 23 Apr 2025 20:32:04 +0200
cmd/getconf: only free at end of -a loop
Found via clang scan-build:
```
cmd/getconf.c:204:6: warning: Attempt to free released memory [unix.Malloc]
204 | free(buf);
| ^~~~~~~~~
cmd/getconf.c:216:21: warning: Attempt to free released memory [unix.Malloc]
216 | char *buf_ret = realloc(buf, buflen_ret);
| ^~~~~~~~~~~~~~~~~~~~~~~~
cmd/getconf.c:232:17: warning: Use of memory after it is freed [unix.Malloc]
232 | size_t ret = confstr(confstr_vars[i].value, buf, buflen);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3 warnings generated.
```
Diffstat:
1 file changed, 0 insertions(+), 3 deletions(-)
diff --git a/cmd/getconf.c b/cmd/getconf.c
@@ -201,7 +201,6 @@ main(int argc, char *argv[])
confstr_vars[i].value,
confstr_vars[i].name,
strerror(errno));
- free(buf);
err = 1;
continue;
}
@@ -220,7 +219,6 @@ main(int argc, char *argv[])
"getconf: error: Failed to allocate %zd bytes buffer for confstr: %s\n",
buflen,
strerror(errno));
- free(buf);
err = 1;
continue;
}
@@ -240,7 +238,6 @@ main(int argc, char *argv[])
confstr_vars[i].name,
buflen,
strerror(errno));
- free(buf);
err = 1;
continue;
}