kdrive: use calloc() instead of malloc()
Using calloc() instead of malloc() as preventive measure, so there never can be any hidden bugs or leaks due uninitialized memory. The extra cost of using this compiler intrinsic should be practically impossible to measure - in many cases a good compiler can even deduce if certain areas really don't need to be zero'd (because they're written to right after allocation) and create more efficient machine code. The code pathes in question are pretty cold anyways, so it's probably not worth even thinking about potential extra runtime costs. Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
This commit is contained in:
parent
e87d41a91d
commit
30d65cd9f1
|
@ -76,9 +76,7 @@ ephyrInitialize(KdCardInfo * card, EphyrPriv * priv)
|
|||
Bool
|
||||
ephyrCardInit(KdCardInfo * card)
|
||||
{
|
||||
EphyrPriv *priv;
|
||||
|
||||
priv = (EphyrPriv *) malloc(sizeof(EphyrPriv));
|
||||
EphyrPriv *priv = calloc(1, sizeof(EphyrPriv));
|
||||
if (!priv)
|
||||
return FALSE;
|
||||
|
||||
|
|
|
@ -144,11 +144,10 @@ ephyr_glamor_build_glsl_prog(GLuint vs, GLuint fs)
|
|||
glLinkProgram(prog);
|
||||
glGetProgramiv(prog, GL_LINK_STATUS, &ok);
|
||||
if (!ok) {
|
||||
GLchar *info;
|
||||
GLint size;
|
||||
|
||||
glGetProgramiv(prog, GL_INFO_LOG_LENGTH, &size);
|
||||
info = malloc(size);
|
||||
GLchar *info = calloc(1, size);
|
||||
|
||||
glGetProgramInfoLog(prog, size, NULL, info);
|
||||
ErrorF("Failed to link: %s\n", info);
|
||||
|
@ -352,7 +351,7 @@ ephyr_glamor_screen_init(xcb_window_t win, xcb_visualid_t vid)
|
|||
|
||||
glamor = calloc(1, sizeof(struct ephyr_glamor));
|
||||
if (!glamor) {
|
||||
FatalError("malloc");
|
||||
FatalError("calloc");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
|
|
@ -533,7 +533,6 @@ hostx_init(void)
|
|||
uint32_t pixel;
|
||||
int index;
|
||||
char *tmpstr;
|
||||
char *class_hint;
|
||||
size_t class_len;
|
||||
xcb_screen_t *xscreen;
|
||||
xcb_rectangle_t rect = { 0, 0, 1, 1 };
|
||||
|
@ -658,7 +657,7 @@ hostx_init(void)
|
|||
if (tmpstr && (!ephyrResNameFromCmd))
|
||||
ephyrResName = tmpstr;
|
||||
class_len = strlen(ephyrResName) + 1 + strlen("Xephyr") + 1;
|
||||
class_hint = malloc(class_len);
|
||||
char *class_hint = calloc(1, class_len);
|
||||
if (class_hint) {
|
||||
strcpy(class_hint, ephyrResName);
|
||||
strcpy(class_hint + strlen(ephyrResName) + 1, "Xephyr");
|
||||
|
|
|
@ -135,7 +135,7 @@ KdXVScreenInit(ScreenPtr pScreen, KdVideoAdaptorPtr adaptors, int num)
|
|||
KdXvScreenKey = XvGetScreenKey();
|
||||
PortResource = XvGetRTPort();
|
||||
|
||||
ScreenPriv = malloc(sizeof(KdXVScreenRec));
|
||||
ScreenPriv = calloc(1, sizeof(KdXVScreenRec));
|
||||
dixSetPrivate(&pScreen->devPrivates, &KdXVScreenPrivateKey, ScreenPriv);
|
||||
|
||||
if (!ScreenPriv)
|
||||
|
@ -723,7 +723,7 @@ KdXVEnlistPortInWindow(WindowPtr pWin, XvPortRecPrivatePtr portPriv)
|
|||
}
|
||||
|
||||
if (!winPriv) {
|
||||
winPriv = malloc(sizeof(KdXVWindowRec));
|
||||
winPriv = calloc(1, sizeof(KdXVWindowRec));
|
||||
if (!winPriv)
|
||||
return BadAlloc;
|
||||
winPriv->PortRec = portPriv;
|
||||
|
|
Loading…
Reference in New Issue