Re: Possible memory leak

[email protected] Thu, 13 Oct 2016 04:39:19 +0000
Newsgroups gmane.os.openbsd.sparc
Message-ID <[email protected]>
On Wed, Oct 12, 2016 at 04:26:20PM -0400, Joe Nosay wrote:
> Where in the code is the problem?
> 
> On Tue, Oct 11, 2016 at 11:49 PM, <[email protected]> wrote:
> 

836	vd = malloc(sizeof(struct vdsk_dring), M_DEVBUF, M_NOWAIT);
837	if (vd == NULL)
838		return NULL;
839

assuming this suceeds...

840	size = roundup(nentries * sizeof(struct vd_desc), PAGE_SIZE);
841
842	if (bus_dmamap_create(t, size, 1, size, 0,
843	    BUS_DMA_NOWAIT | BUS_DMA_ALLOCNOW, &vd->vd_map) != 0)
844		return (NULL);

but this fails.

Now we return NULL, due to failure. but there's no reference to vd
which will allow us to free it later.

(I may be misunderstanding what bus_dmamap_create does, but probably not.