[CRIU] [PATCH] irmap: don't leak irmap objects in --irmap-scan-path

Tycho Andersen tycho.andersen at canonical.com
Tue Sep 22 12:38:47 PDT 2015


On Tue, Sep 22, 2015 at 10:25:14PM +0300, Pavel Emelyanov wrote:
> On 09/22/2015 10:13 PM, Tycho Andersen wrote:
> > On Tue, Sep 22, 2015 at 09:47:07PM +0300, Pavel Emelyanov wrote:
> >>
> >>> @@ -268,9 +268,14 @@ char *irmap_lookup(unsigned int s_dev, unsigned long i_ino)
> >>>  	list_for_each_entry(o, &opts.irmap_scan_paths, node) {
> >>>  		struct irmap *ir;
> >>>  
> >>> -		ir = xzalloc(sizeof(*ir));
> >>> -		if (!ir)
> >>> -			goto out;
> >>> +		if (!o->ir) {
> >>> +			ir = xzalloc(sizeof(*ir));
> >>> +			if (!ir)
> >>> +				goto out;
> >>> +			o->ir = ir;
> >>> +		} else {
> >>> +			ir = o->ir;
> >>
> >> OK, and since we keep the ir on o all the time, is there any reason why
> >> we don't embed the struct irmap directly into the struct irmap_path_opt? :)
> > 
> > You mean just get rid of struct irmap_path_opt entirely? We could,
> > although we'd have to add a list_head to irmap, or just use realloc to
> > allocate the array or the argument list provided by --irmap-scan-path.
> > I'm fine with either of those, let me know which you prefer.
> 
> Well, not get rid entirely :) I actually had smth like this in mind:

Ah, ok, I'll fix and resend this.

Thanks,

Tycho

> struct irmap_path_opt {
> 	struct ir;
> 	struct list_head list;
> }
> 
> irmap_path_scan_add(char *path)
> {
> 	irmap = xmalloc();
> 	irmap->ir.path = path;
> 	irmap->ir.nr_kids = -1;
> 	list_add(...);
> }
> 
> and
> 
> irmap_lookup()
> {
> 	...
> 	irmap_scan(&opt->ir, ...);
> 	...
> }
> 
> --- Pavel


More information about the CRIU mailing list