[PATCH] setvareq: do not return a freed pointer

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

2011-06-19  Jim Meyering  <meyering@xxxxxxxxxx>

	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@xxxxxxxxxx>
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@xxxxxxxxxx>
---
 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
--
To unsubscribe from this list: send the line "unsubscribe dash" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [LARTC]     [Bugtraq]     [Yosemite Forum]     [Photo]

  Powered by Linux