setvareq: do not return a freed pointer
PATCH 1/1 setvareq: do not return a freed pointer
This change may be technically unnecessary, but it's worth the minuscule cost of the initialization.
2011-06-19 Jim Meyering <[email protected]>
setvareq: do not return a freed pointer
* src/var.c (setvareq): Don't return a freed pointer. In at least one case (when called from unsetvar), the return value is not used, but better not to risk it, and to placate static analyzers. Spotted by coverity.
Exercise via dash -c 'j=; unset j'
From e91caa66e9f1e449e5ea129d2c1e304e66784e2f Mon Sep 17 00:00:00 2001
From: Jim Meyering <[email protected]>
Date: Sun, 19 Jun 2011 21:28:02 +0200
Subject: [PATCH] setvareq: do not return a freed pointer
* src/var.c (setvareq): Don't return a freed pointer. In at least one case (when called from unsetvar), the return value is not used, but better not to risk it, and to placate static analyzers. Spotted by coverity.
Exercise via dash -c 'j=; unset j'
--- ChangeLog | 9 +++++++++ src/var.c | 1 + 2 files changed, 10 insertions(+), 0 deletions(-)
src/var.c +1 -0
@@ -276,6 +276,7 @@ struct var *setvareq(char *s, int flags) (vp->flags & VSTRFIXED)) == VUNSET) { *vpp = vp->next;ckfree (vp); + vp =NULL ; out_free:if ((flags & (VTEXTFIXED |VSTACK |VNOSAVE )) ==VNOSAVE )ckfree (s);
--
1.7.6.rc2.4.g36bfb.dirty
Quoted 2 lines · Jim Meyering
This change may be technically unnecessary, but it's worth the minuscule cost of the initialization.
I disagree, unless you can do this without adding to the code size.
Thanks,
Signature · 3 lines
Email: Herbert Xu <[email protected]> Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt