void wTextureDestroy(WScreen * scr, WTexture * texture) { int i; int count = 0; unsigned long colors[8]; /* * some stupid servers don't like white or black being freed... */ #define CANFREE(c) (c!=scr->black_pixel && c!=scr->white_pixel && c!=0) switch (texture->any.type) { case WTEX_SOLID: XFreeGC(dpy, texture->solid.light_gc); XFreeGC(dpy, texture->solid.dark_gc); XFreeGC(dpy, texture->solid.dim_gc); if (CANFREE(texture->solid.light.pixel)) colors[count++] = texture->solid.light.pixel; if (CANFREE(texture->solid.dim.pixel)) colors[count++] = texture->solid.dim.pixel; if (CANFREE(texture->solid.dark.pixel)) colors[count++] = texture->solid.dark.pixel; break; case WTEX_PIXMAP: RReleaseImage(texture->pixmap.pixmap); break; case WTEX_MHGRADIENT: case WTEX_MVGRADIENT: case WTEX_MDGRADIENT: for (i = 0; texture->mgradient.colors[i] != NULL; i++) { wfree(texture->mgradient.colors[i]); } wfree(texture->mgradient.colors); break; case WTEX_THGRADIENT: case WTEX_TVGRADIENT: case WTEX_TDGRADIENT: RReleaseImage(texture->tgradient.pixmap); break; } if (CANFREE(texture->any.color.pixel)) colors[count++] = texture->any.color.pixel; if (count > 0) { XErrorHandler oldhandler; /* ignore error from buggy servers that don't know how * to do reference counting for colors. */ XSync(dpy, 0); oldhandler = XSetErrorHandler(dummyErrorHandler); XFreeColors(dpy, scr->w_colormap, colors, count, 0); XSync(dpy, 0); XSetErrorHandler(oldhandler); } XFreeGC(dpy, texture->any.gc); wfree(texture); #undef CANFREE }
void filter_passwd(struct passwd *pwd, char *buffer, size_t buflen) { /* Ideally we want to add some means of configuring the * filters that we apply here. For now we'll simply * hard-code a couple of examples. */ /* N.B. there's no means of returning to your caller how much * of buffer you have used up. Thus when stacking NSS modules, * you can't rely on buffer's being available for storing your * updated data -- you don't know whether anyone has had at it * already. * * It is /not/ safe to free members that you are replacing, unless * you are certain that they lie outside of buffer[0:buflen]. * Is it safe simply to malloc more memory? We'll try it. */ printd("pwd = %p, pwd->pw_gecos = %p, buffer = %p[%d]\n", pwd, pwd->pw_gecos, buffer, buflen); #define CANFREE(p) (((p) < buffer) || ((p) > (buffer + buflen))) if (pwd->pw_gecos && strchr(pwd->pw_gecos, '&')) subst(&pwd->pw_gecos, "&", pwd->pw_name, CANFREE(pwd->pw_gecos), pass_capitalize); if (pwd->pw_dir && strchr(pwd->pw_dir, '&')) subst(&pwd->pw_dir, "&", pwd->pw_name, CANFREE(pwd->pw_dir), pass_lowercase); if (pwd->pw_shell && strchr(pwd->pw_shell, '&')) subst(&pwd->pw_shell, "&", pwd->pw_name, CANFREE(pwd->pw_shell), pass_lowercase); return; }