Fix memory leaks in vblank error paths.
authorMichel Dänzer <michel@tungstengraphics.com>
Fri, 15 Jun 2007 08:10:33 +0000 (10:10 +0200)
committerMichel Dänzer <michel@tungstengraphics.com>
Fri, 15 Jun 2007 08:10:33 +0000 (10:10 +0200)
Also use drm_calloc instead of drm_alloc and memset, and use the size of the
struct instead of the size of the pointer for allocation...

linux-core/drm_irq.c
shared-core/i915_irq.c

index 7bdb01b..f73d067 100644 (file)
@@ -518,18 +518,19 @@ int drm_wait_vblank(DRM_IOCTL_ARGS)
 
                spin_unlock_irqrestore(&dev->vbl_lock, irqflags);
 
-               if (!
-                   (vbl_sig =
-                    drm_alloc(sizeof(drm_vbl_sig_t), DRM_MEM_DRIVER))) {
+               vbl_sig = drm_calloc(1, sizeof(drm_vbl_sig_t), DRM_MEM_DRIVER);
+               if (!vbl_sig) {
                        return -ENOMEM;
                }
 
                ret = drm_vblank_get(dev, crtc);
-               if (ret)
+               if (ret) {
+                       drm_free(vbl_sig, sizeof(drm_vbl_sig_t),
+                                DRM_MEM_DRIVER);
                        return ret;
-               atomic_inc(&dev->vbl_signal_pending);
+               }
 
-               memset((void *)vbl_sig, 0, sizeof(*vbl_sig));
+               atomic_inc(&dev->vbl_signal_pending);
 
                vbl_sig->sequence = vblwait.request.sequence;
                vbl_sig->info.si_signo = vblwait.request.signal;
index e91add9..ad2cf9c 100644 (file)
@@ -707,7 +707,7 @@ int i915_vblank_swap(DRM_IOCTL_ARGS)
                return DRM_ERR(EBUSY);
        }
 
-       vbl_swap = drm_calloc(1, sizeof(vbl_swap), DRM_MEM_DRIVER);
+       vbl_swap = drm_calloc(1, sizeof(*vbl_swap), DRM_MEM_DRIVER);
 
        if (!vbl_swap) {
                DRM_ERROR("Failed to allocate memory to queue swap\n");
@@ -717,8 +717,10 @@ int i915_vblank_swap(DRM_IOCTL_ARGS)
        DRM_DEBUG("\n");
 
        ret = drm_vblank_get(dev, pipe);
-       if (ret)
+       if (ret) {
+               drm_free(vbl_swap, sizeof(*vbl_swap), DRM_MEM_DRIVER);
                return ret;
+       }
 
        vbl_swap->drw_id = swap.drawable;
        vbl_swap->pipe = pipe;