Improve error reporting when unmarshalling of message headers fail.
[deb_libnfs.git] / lib / init.c
index 93d1db8b088b3780601d5251b63fb30d71a0e28e..3c0c2de46c2e7c7880b29420cce9f047ffcb4333 100644 (file)
@@ -132,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)