We only need to spend CPU computing a new error string IFF there was an error
[deb_libnfs.git] / lib / init.c
index df3c2aa2bd90cc25a7302907428c362648f7b85e..3c0c2de46c2e7c7880b29420cce9f047ffcb4333 100644 (file)
@@ -57,7 +57,9 @@ struct rpc_context *rpc_init_context(void)
        memset(rpc, 0, sizeof(struct rpc_context));
 
        rpc->magic = RPC_CONTEXT_MAGIC;
-       rpc->encodebuflen = 65536;
+
+       /* Allow 1M of data (for writes) and some */
+       rpc->encodebuflen = 1024 * 1024 + 4096;
        rpc->encodebuf = malloc(rpc->encodebuflen);
        if (rpc->encodebuf == NULL) {
                free(rpc);
@@ -130,16 +132,18 @@ void rpc_set_gid(struct rpc_context *rpc, int gid) {
 void rpc_set_error(struct rpc_context *rpc, char *error_string, ...)
 {
         va_list ap;
+       char *old_error_string = rpc->error_string;
 
        assert(rpc->magic == RPC_CONTEXT_MAGIC);
 
-       if (rpc->error_string != NULL) {
-               free(rpc->error_string);
-       }
         va_start(ap, error_string);
        rpc->error_string = malloc(1024);
        vsnprintf(rpc->error_string, 1024, error_string, ap);
         va_end(ap);
+
+       if (old_error_string != NULL) {
+               free(old_error_string);
+       }
 }
 
 char *rpc_get_error(struct rpc_context *rpc)