aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorScott Anderson <scott@anderso.nz>2019-05-17 13:53:49 +1200
committerSimon Ser <contact@emersion.fr>2019-05-17 08:59:49 +0300
commite9c7aee1740883d0120fabdd6120f52dfbb5027e (patch)
tree6515f762c9a730b21155dfd1278490f9c77e11dc
parent7bf0cc02ed3323224e0cfc19cfe9118990bae729 (diff)
downloadexternal_drm_info-e9c7aee1740883d0120fabdd6120f52dfbb5027e.tar.gz
external_drm_info-e9c7aee1740883d0120fabdd6120f52dfbb5027e.tar.bz2
external_drm_info-e9c7aee1740883d0120fabdd6120f52dfbb5027e.zip
Fix some error paths
Especially fixes leaks and errors when passed something that is not a DRM device.
-rw-r--r--json.c21
1 files changed, 13 insertions, 8 deletions
diff --git a/json.c b/json.c
index 5960dae..7361493 100644
--- a/json.c
+++ b/json.c
@@ -92,14 +92,14 @@ static struct json_object *new_json_object_uint64(uint64_t u)
static struct json_object *driver_info(int fd)
{
- struct json_object *obj = json_object_new_object();
-
drmVersion *ver = drmGetVersion(fd);
if (!ver) {
perror("drmGetVersion");
return NULL;
}
+ struct json_object *obj = json_object_new_object();
+
json_object_object_add(obj, "name", json_object_new_string(ver->name));
json_object_object_add(obj, "desc", json_object_new_string(ver->desc));
@@ -297,14 +297,14 @@ static struct json_object *path_info(int fd, uint32_t blob_id)
static struct json_object *properties_info(int fd, uint32_t id, uint32_t type)
{
- struct json_object *obj = json_object_new_object();
-
drmModeObjectProperties *props = drmModeObjectGetProperties(fd, id, type);
if (!props) {
perror("drmModeObjectGetProperties");
return NULL;
}
+ struct json_object *obj = json_object_new_object();
+
for (uint32_t i = 0; i < props->count_props; ++i) {
drmModePropertyRes *prop = drmModeGetProperty(fd, props->props[i]);
if (!prop) {
@@ -526,14 +526,14 @@ static struct json_object *crtcs_info(int fd, drmModeRes *res)
static struct json_object *planes_info(int fd)
{
- struct json_object *arr = json_object_new_array();
-
drmModePlaneRes *res = drmModeGetPlaneResources(fd);
if (!res) {
perror("drmModeGetPlaneResources");
return NULL;
}
+ struct json_object *arr = json_object_new_array();
+
for (uint32_t i = 0; i < res->count_planes; ++i) {
drmModePlane *plane = drmModeGetPlane(fd, res->planes[i]);
if (!plane) {
@@ -571,14 +571,14 @@ static struct json_object *planes_info(int fd)
static struct json_object *node_info(const char *path)
{
- struct json_object *obj = json_object_new_object();
-
int fd = open(path, O_RDONLY);
if (fd < 0) {
perror(path);
return NULL;
}
+ struct json_object *obj = json_object_new_object();
+
// Get driver info before getting resources, as it'll try to enable some
// DRM client capabilities
json_object_object_add(obj, "driver", driver_info(fd));
@@ -588,6 +588,8 @@ static struct json_object *node_info(const char *path)
drmModeRes *res = drmModeGetResources(fd);
if (!res) {
perror("drmModeGetResources");
+ close(fd);
+ json_object_put(obj);
return NULL;
}
@@ -617,6 +619,9 @@ struct json_object *drm_info(char *paths[])
break;
struct json_object *dev = node_info(path);
+ if (!dev)
+ continue;
+
json_object_object_add(obj, path, dev);
}
} else {