OSDN Git Service

modetest: fix Segmentation fault
authorJoonyoung Shim <jy0922.shim@samsung.com>
Mon, 13 Apr 2015 08:32:14 +0000 (17:32 +0900)
committerEmil Velikov <emil.l.velikov@gmail.com>
Tue, 28 Apr 2015 10:27:18 +0000 (11:27 +0100)
If use -P option without -s option, the program segfaults due to
dev.mode.bo being NULL.

Signed-off-by: Joonyoung Shim <jy0922.shim@samsung.com>
[Emil Velikov: Tweak the commit message.]
Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
tests/modetest/modetest.c

index e646790..966c2b6 100644 (file)
@@ -1119,6 +1119,12 @@ static void set_mode(struct device *dev, struct pipe_arg *pipes, unsigned int co
        dev->mode.fb_id = fb_id;
 }
 
+static void clear_mode(struct device *dev)
+{
+       if (dev->mode.bo)
+               bo_destroy(dev->mode.bo);
+}
+
 static void set_planes(struct device *dev, struct plane_arg *p, unsigned int count)
 {
        unsigned int i;
@@ -1642,7 +1648,8 @@ int main(int argc, char **argv)
                if (test_cursor)
                        clear_cursors(&dev);
 
-               bo_destroy(dev.mode.bo);
+               if (count)
+                       clear_mode(&dev);
        }
 
        free_resources(dev.resources);