This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH 2/3] Replace remaining cleanups in fbsd-nat.c.


On Tuesday, August 08, 2017 11:16:28 AM Simon Marchi wrote:
> Hi John,
> 
> > @@ -84,20 +92,17 @@ fbsd_find_memory_regions (struct target_ops *self,
> >  			  find_memory_region_ftype func, void *obfd)
> >  {
> >    pid_t pid = ptid_get_pid (inferior_ptid);
> > -  struct kinfo_vmentry *vmentl, *kve;
> > +  struct kinfo_vmentry *kve;
> >    uint64_t size;
> > -  struct cleanup *cleanup;
> >    int i, nitems;
> > 
> > -  vmentl = kinfo_getvmmap (pid, &nitems);
> > +  std::unique_ptr<struct kinfo_vmentry, free_deleter<struct 
> > kinfo_vmentry>>
> > +    vmentl (kinfo_getvmmap (pid, &nitems));
> 
> Doesn't this essentially do the same thing as gdb::unique_xmalloc_ptr, 
> since xfree calls free?

Well, this calls an API in a system library that allocates memory via libc's
malloc() and requires it to be free'd via libc's free() rather than any
interpositions.  Thus, it isn't allocated via xmalloc() and that is why
the existing code uses free() rather than xfree().

> > @@ -392,7 +392,7 @@ fbsd_xfer_partial (struct target_ops *ops, enum
> > target_object object,
> >  #endif
> >      case TARGET_OBJECT_AUXV:
> >        {
> > -	struct cleanup *cleanup = make_cleanup (null_cleanup, NULL);
> > +	gdb::unique_xmalloc_ptr<unsigned char> buf_storage(nullptr);
> 
> You don't need to initialize explicitly to nullptr, that's the default 
> value.  But if you still want to, then add a space before parenthesis 
> :).

Oh, duh.

> Otherwise, gdb::byte_vector with a .resize() would probably be 
> appropriate to use here.

Ok, I'll rework it with that.

-- 
John Baldwin


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]