From 48198970ce449165fe1c7294108ca3afc775563d Mon Sep 17 00:00:00 2001 From: Adam Jackson Date: Tue, 29 Nov 2005 20:02:34 +0000 Subject: Error checking for drmStrdup (Tilman Sauerbeck) --- libdrm/xf86drm.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/libdrm/xf86drm.c b/libdrm/xf86drm.c index 82cf54ff..2eed8eb4 100644 --- a/libdrm/xf86drm.c +++ b/libdrm/xf86drm.c @@ -164,12 +164,17 @@ void drmFree(void *pt) /* drmStrdup can't use strdup(3), since it doesn't call _DRM_MALLOC... */ static char *drmStrdup(const char *s) { - char *retval = NULL; + char *retval; + + if (!s) + return NULL; + + retval = _DRM_MALLOC(strlen(s)+1); + if (!retval) + return NULL; + + strcpy(retval, s); - if (s) { - retval = _DRM_MALLOC(strlen(s)+1); - strcpy(retval, s); - } return retval; } -- cgit v1.2.3