[pacman-dev] [PATCH 4/4] Move NULL check before dereference

Silvan Jegen s.jegen at gmail.com
Tue Jan 28 12:58:52 EST 2014


On Tue, Jan 28, 2014 at 12:32:13PM -0500, Andrew Gregory wrote:
> On 01/28/14 at 05:50pm, Silvan Jegen wrote:
> > Signed-off-by: Silvan Jegen <s.jegen at gmail.com>
> > ---
> >  src/pacman/pacman.c | 12 ++++++------
> >  1 file changed, 6 insertions(+), 6 deletions(-)
> > 
> > diff --git a/src/pacman/pacman.c b/src/pacman/pacman.c
> > index 7329f0f..1d821ef 100644
> > --- a/src/pacman/pacman.c
> > +++ b/src/pacman/pacman.c
> > @@ -262,13 +262,13 @@ static void setuseragent(void)
> >  static void cleanup(int ret)
> >  {
> >  	/* free alpm library resources */
> 
> This comment applies specifically to the alpm_release call and either
> needs to be moved with it or deleted.

My bad.


> > -	if(config->handle && alpm_release(config->handle) == -1) {
> > -		pm_printf(ALPM_LOG_ERROR, "error releasing alpm library\n");
> > -	}
> > -
> > -	/* free memory */
> > -	FREELIST(pm_targets);
> >  	if(config) {
> > +		if(config->handle && alpm_release(config->handle) == -1) {
> > +			pm_printf(ALPM_LOG_ERROR, "error releasing alpm library\n");
> > +		}
> > +
> > +		/* free memory */
> > +		FREELIST(pm_targets);
> 
> pm_targets is independent of config and needs to be freed whether
> config is NULL or not.

Ditto.

A corrected version of the patch can be found below. Hope I got it right
this time.


-->8-- (for use with git am --scissors)
Subject: [PATCH v2] Move NULL check before dereference

Signed-off-by: Silvan Jegen <s.jegen at gmail.com>
---
 src/pacman/pacman.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/src/pacman/pacman.c b/src/pacman/pacman.c
index 7329f0f..3ecced5 100644
--- a/src/pacman/pacman.c
+++ b/src/pacman/pacman.c
@@ -261,18 +261,18 @@ static void setuseragent(void)
  */
 static void cleanup(int ret)
 {
-	/* free alpm library resources */
-	if(config->handle && alpm_release(config->handle) == -1) {
-		pm_printf(ALPM_LOG_ERROR, "error releasing alpm library\n");
-	}
-
-	/* free memory */
-	FREELIST(pm_targets);
 	if(config) {
+		/* free alpm library resources */
+		if(config->handle && alpm_release(config->handle) == -1) {
+			pm_printf(ALPM_LOG_ERROR, "error releasing alpm library\n");
+		}
+
 		config_free(config);
 		config = NULL;
 	}
 
+	/* free memory */
+	FREELIST(pm_targets);
 	exit(ret);
 }
 
-- 
1.8.5.3



More information about the pacman-dev mailing list