Пример #1
0
/*
 * Free memory of resource.
 * NB, we don't need to worry about freeing any references
 * to other resources as they will be freed when that
 * resource chain is traversed.  Mainly we worry about freeing
 * allocated strings (names).
 */
void free_resource(RES *sres, int type)
{
   RES *nres;
   URES *res = (URES *)sres;

   if (res == NULL)
      return;

   /*
    * Common stuff -- free the resource name
    */
   nres = (RES *)res->dir_res.hdr.next;
   if (res->dir_res.hdr.name) {
      free(res->dir_res.hdr.name);
   }
   if (res->dir_res.hdr.desc) {
      free(res->dir_res.hdr.desc);
   }

   switch (type) {
   case R_DIRECTOR:
      if (res->dir_res.address) {
         free(res->dir_res.address);
      }
      free_tls_t(res->dir_res.tls);
      break;
   case R_CONSOLE:
      if (res->con_res.password.value) {
         free(res->con_res.password.value);
      }
      free_tls_t(res->con_res.tls);
      break;
   case R_CONSOLE_FONT:
      if (res->con_font.fontface) {
         free(res->con_font.fontface);
      }
      break;
   default:
      printf(_("Unknown resource type %d\n"), type);
   }
   /*
    * Common stuff again -- free the resource, recurse to next one
    */
   free(res);
   if (nres) {
      free_resource(nres, type);
   }
}
Пример #2
0
/*
 * Free memory of resource.
 * NB, we don't need to worry about freeing any references
 * to other resources as they will be freed when that
 * resource chain is traversed.  Mainly we worry about freeing
 * allocated strings (names).
 */
void free_resource(RES *sres, int type)
{
   RES *nres;
   URES *res = (URES *)sres;

   if (res == NULL)
      return;

   /* common stuff -- free the resource name */
   nres = (RES *)res->res_dir.hdr.next;
   if (res->res_dir.hdr.name) {
      free(res->res_dir.hdr.name);
   }
   if (res->res_dir.hdr.desc) {
      free(res->res_dir.hdr.desc);
   }

   switch (type) {
   case R_CONSOLE:
      if (res->res_cons.rc_file) {
         free(res->res_cons.rc_file);
      }
      if (res->res_cons.history_file) {
         free(res->res_cons.history_file);
      }
      free_tls_t(res->res_cons.tls);
      break;
   case R_DIRECTOR:
      if (res->res_dir.address) {
         free(res->res_dir.address);
      }
      free_tls_t(res->res_dir.tls);
      break;
   default:
      printf(_("Unknown resource type %d\n"), type);
   }
   /* Common stuff again -- free the resource, recurse to next one */
   free(res);
   if (nres) {
      free_resource(nres, type);
   }
}