[PATCH] Fix a memory leak in object-attribute evaluation

Jim Meyering jim at meyering.net
Tue Oct 12 17:30:58 UTC 2010


Jeff Darcy wrote:
> I'm not super-happy with the approach I used for this, but can't think
> of anything better right now.  Bear in mind that the site-field and
> link-following pieces are both kind of under construction right now, so
> their memory-ownership rules are likely to change soon anyway.

Quick fix ;-)
I confirm that it does the job.
However, it does add this new warning:

  query.c: In function 'string_value':
  query.c:232: warning: assignment discards qualifiers from pointer target type

> Subject: [PATCH] Fix a memory leak in object-attribute evaluation (found by Jim).
...
> diff --git a/query.h b/query.h
> index 20a27c9..d541dd7 100644
> --- a/query.h
> +++ b/query.h
> @@ -41,6 +41,7 @@ typedef struct _value {
>  			struct _value *right;
>  		} as_tree;
>  	};
> +	char *resolved;	/* saved result for T_OFIELD/T_SFIELD/T_LINK */

The new warning can be avoided if you don't mind adding a "const" here,
but as with other recent changes, that requires a cast where this
potentially malloc'd buffer is freed:

>  } value_t;
>
>  typedef struct {
> diff --git a/query.leg b/query.leg
...
> +	if (v->resolved) {
> +		printf("freeing resolved string \"%s\" (%p)\n",
> +			v->resolved, v->resolved);
> +	}
> +	free(v->resolved);

... here.


More information about the iwhd-devel mailing list