when nfs_set_error is called with error_string being the result of a lower layer
problem so it is passed as "rpc_get_error()"
This meant that since free that nfs->rpc->error_string before we reference it a few lines further down in the vasprintf(..., error_string,
adn memory corruption triggers.
Valgrind found this, Valgrind rules!
printf("Failed to mount nfs share : %s\n", nfs_get_error(nfs));
exit(10);
}
- printf("mounted share successfully\n");
+ printf("mounted share successfully %s\n", nfs_get_error(nfs));
ret = nfs_stat(nfs, NFSFILE, &st);
void nfs_set_error(struct nfs_context *nfs, char *error_string, ...)
{
va_list ap;
- char *str;
+ char *str = NULL;
+ va_start(ap, error_string);
+ vasprintf(&str, error_string, ap);
if (nfs->rpc->error_string != NULL) {
free(nfs->rpc->error_string);
}
- va_start(ap, error_string);
- vasprintf(&str, error_string, ap);
nfs->rpc->error_string = str;
va_end(ap);
}