From 4226fd1b67d1f1571ca21128eaf4a7112bc1ea06 Mon Sep 17 00:00:00 2001 From: Roland McGrath Date: Sat, 29 Sep 2001 04:28:55 +0000 Subject: 2001-09-28 Roland McGrath * decode.c (store_std_leaf_decode): Actually copy data into MISC. Don't call malloc for it when MISC_LEN is zero, just store null. --- libstore/decode.c | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) (limited to 'libstore') diff --git a/libstore/decode.c b/libstore/decode.c index 33e99492..cc063d34 100644 --- a/libstore/decode.c +++ b/libstore/decode.c @@ -1,7 +1,7 @@ /* Store wire decoding - Copyright (C) 1996, 1997, 1998 Free Software Foundation, Inc. - Written by Miles Bader + Copyright (C) 1996,97,98,2001 Free Software Foundation, Inc. + Written by Miles Bader This file is part of the GNU Hurd. The GNU Hurd is free software; you can redistribute it and/or @@ -64,21 +64,28 @@ store_std_leaf_decode (struct store_enc *enc, if (name_len > 0 && enc->data[enc->cur_data + name_len - 1] != '\0') return EINVAL; /* Name not terminated. */ - misc = malloc (misc_len); - if (! misc) - return ENOMEM; - if (name_len > 0) { name = strdup (enc->data + enc->cur_data); if (! name) + return ENOMEM; + } + else + name = 0; + + if (misc_len > 0) + { + misc = malloc (misc_len); + if (! misc) { - free (misc); + if (name) + free (name); return ENOMEM; } + memcpy (misc, enc->data + enc->cur_data + name_len, misc_len); } else - name = 0; + misc = 0; /* Read encoded ports (be careful to deallocate this if we barf). */ port = enc->ports[enc->cur_port++]; @@ -87,7 +94,8 @@ store_std_leaf_decode (struct store_enc *enc, if (err) { mach_port_deallocate (mach_task_self (), port); - free (misc); + if (misc) + free (misc); if (name) free (name); } -- cgit v1.2.3