DASH Shell discussions
 help / color / mirror / Atom feed
* [PATCH] setvareq: do not return a freed pointer
@ 2011-06-19 19:30 Jim Meyering
  2011-07-08  8:57 ` Herbert Xu
  0 siblings, 1 reply; 2+ messages in thread
From: Jim Meyering @ 2011-06-19 19:30 UTC (permalink / raw)
  To: dash

This change may be technically unnecessary, but it's worth
the minuscule cost of the initialization.

2011-06-19  Jim Meyering  <meyering@redhat.com>

	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 <meyering@redhat.com>
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'

Signed-off-by: Jim Meyering <meyering@redhat.com>
---
 ChangeLog |    9 +++++++++
 src/var.c |    1 +
 2 files changed, 10 insertions(+), 0 deletions(-)

diff --git a/src/var.c b/src/var.c
index ecc8c90..34c5d32 100644
--- a/src/var.c
+++ b/src/var.c
@@ -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

^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2011-07-08  8:57 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-06-19 19:30 [PATCH] setvareq: do not return a freed pointer Jim Meyering
2011-07-08  8:57 ` Herbert Xu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox