don't crash Xserver on malloc() failure anymore (XNFasprintf)

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
This commit is contained in:
Enrico Weigelt, metux IT consult
2025-11-06 16:56:21 +01:00
committed by Enrico Weigelt
parent 45f03ac5d8
commit e237014dc6
3 changed files with 16 additions and 6 deletions

View File

@@ -203,11 +203,14 @@ ati_gdev_subdriver(pointer options)
}
if (chip_family == ATI_CHIP_FAMILY_Radeon) {
char *busid;
char *busid = NULL;
XNFasprintf(&busid, "pci:%04x:%02x:%02x.%d",
if (asprintf(&busid, "pci:%04x:%02x:%02x.%d",
device->domain, device->bus, device->dev,
device->func);
device->func) == -1) {
ErrorF("ati: malloc() failed\n");
continue;
}
if (busid) {
int fd = drmOpen(NULL, busid);

View File

@@ -2843,7 +2843,11 @@ Bool drmmode_pre_init(ScrnInfoPtr pScrn, drmmode_ptr drmmode, int cpp)
drmmode_clones_init(pScrn, drmmode, mode_res);
bus_id_string = DRICreatePCIBusID(info->PciInfo);
XNFasprintf(&provider_name, "%s @ %s", pScrn->chipset, bus_id_string);
if (asprintf(&provider_name, "%s @ %s", pScrn->chipset, bus_id_string) == -1) {
xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "malloc() failed\n");
return FALSE;
}
free(bus_id_string);
xf86ProviderSetup(pScrn, NULL, provider_name);
free(provider_name);

View File

@@ -1530,8 +1530,11 @@ static int radeon_get_drm_master_fd(ScrnInfoPtr pScrn)
}
#endif
XNFasprintf(&busid, "pci:%04x:%02x:%02x.%d",
dev->domain, dev->bus, dev->dev, dev->func);
if (asprintf(&busid, "pci:%04x:%02x:%02x.%d",
dev->domain, dev->bus, dev->dev, dev->func) == -1) {
xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "malloc() failed\n");
return -1;
}
#ifdef __DragonFly__
/* On DragonFlyBSD Appropriate kernel drivers need to be loaded before