Guest User

cache segfaults because of array declaration?

a guest
Nov 24th, 2010
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.32 KB | None | 0 0
  1. gchar *deskmenu_check_file_cache (gchar *filename){
  2.  
  3. gboolean cached = FALSE;
  4.  
  5. gchar **cache_name;
  6.  
  7. gchar **cache_file;
  8.  
  9. gchar *t = NULL;
  10.  
  11. //segfaults here, most likely because of how I made the arrays
  12.  
  13.  
  14.  
  15. g_printf("%s\n", filename);
  16.  
  17.  
  18.  
  19. if (!filename) {
  20.  
  21.         /*
  22.  
  23.         set 0,0 & 0,1 to be the default config
  24.  
  25.         check to see given argument for filename
  26.  
  27.         set default filename to be [configdir]/compiz/deskmenu/menu.xml
  28.  
  29.         create it if don't exist
  30.  
  31.         */
  32.  
  33.         filename = g_build_path (G_DIR_SEPARATOR_S,
  34.  
  35.                                    g_get_user_config_dir (),
  36.  
  37.                                    "compiz",
  38.  
  39.                                    "deskmenu",
  40.  
  41.                                    "menu.xml",
  42.  
  43.                                    NULL);
  44.  
  45.  
  46.  
  47.     if (!g_file_get_contents (filename, &cache_file[0], NULL, NULL) && !cache_file[0])
  48.  
  49.         {
  50.  
  51.             const gchar* const *cursor = g_get_system_config_dirs ();
  52.  
  53.             gchar *path = NULL;
  54.  
  55.             while (*cursor)
  56.  
  57.             {
  58.  
  59.                 g_free (path);
  60.  
  61.                 path = g_strdup (*cursor);
  62.  
  63.                 filename = g_build_path (G_DIR_SEPARATOR_S,
  64.  
  65.                                         path,
  66.  
  67.                                         "compiz",
  68.  
  69.                                         "deskmenu",
  70.  
  71.                                         "menu.xml",
  72.  
  73.                                         NULL);
  74.  
  75.        
  76.  
  77.                 if (g_file_get_contents (filename, &cache_file[0], NULL, NULL))
  78.  
  79.                 {
  80.  
  81.                     cache_name[0] = filename;
  82.  
  83.                     g_free (path);
  84.  
  85.                     g_free (filename);
  86.  
  87.                     t = g_strdup(cache_file[0]);
  88.  
  89.                     break;
  90.  
  91.                 }
  92.  
  93.                     cursor++;
  94.  
  95.             }
  96.  
  97.         }
  98.  
  99.         else
  100.  
  101.         {
  102.  
  103.             cache_name[0] = filename;
  104.  
  105.             g_free (filename);
  106.  
  107.             t = cache_file[0];
  108.  
  109.         }
  110.  
  111.     }
  112.  
  113.     else{
  114.  
  115.         int i;
  116.  
  117.         i = 0;
  118.  
  119.         //search cache
  120.  
  121.         while(cache_name[i]){
  122.  
  123.             if(filename == cache_name[i]){
  124.  
  125.                 cached = TRUE;
  126.  
  127.                 t = cache_file[i];
  128.  
  129.                 break;
  130.  
  131.             }
  132.  
  133.         }
  134.  
  135.         //cache file if it isn't in the cache
  136.  
  137.         if (!cached){
  138.  
  139.             if (g_file_get_contents (filename, &cache_file[i], NULL, NULL))
  140.  
  141.                 {
  142.  
  143.                     cache_name[i] = filename;
  144.  
  145.                     t = cache_file[i];
  146.  
  147.                 }
  148.  
  149.                 else {
  150.  
  151.                     if (cache_name[0] && cache_file[0])
  152.  
  153.                     {
  154.  
  155.                         g_print("Couldn't find specified file, loading default...");
  156.  
  157.                         t = cache_file[0];
  158.  
  159.                     }
  160.  
  161.                     else
  162.  
  163.                     {
  164.  
  165.                         g_printerr ("Couldn't find a menu file\n");
  166.  
  167.                         exit (1);
  168.  
  169.                     }
  170.  
  171.                 }
  172.  
  173.         }
  174.  
  175.         g_free (filename);
  176.  
  177.     }
  178.  
  179. return t;
  180.  
  181. }
Advertisement
Add Comment
Please, Sign In to add comment