2

我在 Splint 文档中搜索了“新鲜存储”,并发现了它的提及,但没有正式的定义。我理解并正在使用其他修饰符,例如 null 或 only。我只是不确定什么是新存储。

情况是这样的:

void output_system_information(unsigned int frequency, unsigned int duration) { 

   unsigned int intervals = duration/frequency;                                  

   /* here I allocate some storage */                                                                              
   System * my_system = malloc(sizeof(System));                                  

   SystemInfo* current, * total;                                                 

   if (my_system == NULL) {                                                      
     fprintf(stderr, "%s\n", "Aborting: failed malloc in output_system_informatioin");
     exit(EXIT_FAILURE);                                                         
   }                                                                             

   /* and here I initialize is in that function */                                              
   init_system(my_system);      
   total = tally_system_info(frequency, duration, my_system);                    
   current = my_system->get_system_info();                                       

   /* Here I've removed a ton of print-line statements so that you don't have to see them */

   /* then the members and the struct get freed in this here dtor */
   delete_system(my_system);                                                     
   free(current);                                                                
   free(total);                                                                  

   return;                                                                       
}            

这是一个家庭作业,但这个问题不必直接与家庭作业有关。这是一个夹板问题。

4

1 回答 1

1

新存储一词是指刚刚为您的程序分配的内存缓冲区。

警告“未释放新存储”只是“仅未释放存储”的特例,当缓冲区由相同的函数分配但未能释放它时。

于 2012-01-30T17:38:13.543 回答