...
Code Block |
---|
|
int main(int argc, char const *argv[]) {
char *buff;
buff = (char *)malloc(BUFSIZEBUFSIZ);
if (!buff) {
/* handle error condition */
}
/* ... */
free(buff);
/* ... */
strncpy(buff, argv[1], BUFSIZEBUFSIZ-1);
}
|
Compliant Solution
Do not free the memory until it is no longer required.
Code Block |
---|
|
int main(int argc, char const *argv[]) {
char *buff;
buff = (char *)malloc(BUFSIZEBUFSIZ);
if (!buff) {
/* handle error condition */
}
/* ... */
strncpy(buff, argv[1], BUFSIZEBUFSIZ-1);
/* ... */
free(buff);
}
|
...