2012-01-30 62 views
2

我已經搜索了「新鮮存儲」的Splint文檔,並且發現了它,但沒有正式的定義。其他修飾符,如null或only,我理解並正在使用。我只是不確定什麼是新鮮的存儲空間。什麼是Splint中的「Fresh Storage」?

的情況是這樣的:

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;                  
}    

這是一個家庭作業,但這個問題並沒有直接與功課要做。這是一個夾板問題。

回答

1

術語新鮮存儲是指一個內存緩衝區,其中剛分配給您的程序

警告「沒有公佈貯藏保鮮」是只是一個特例「只有存儲沒有公佈」,當緩衝區是由無法釋放它同樣的功能分配。

+0

你怎麼知道的?你能參考一個段落嗎?就這樣,我環顧了斯普林特手冊,並沒有找到這樣的定義。也許我只是需要再次檢查... – Ziggy 2012-02-03 23:37:04

+1

在這裏你可以閱讀[Unshared References](http://www.hawk.org/manual/html/all.html#_Toc534974960)。 我認爲這個例子非常簡單明瞭。 Splint發佈了一個_「返回之前沒有釋放的新鮮存儲」_因爲_「新鮮的存儲被分配了」_在這一行:'int * m =(int *)malloc(sizeof(int));' – 2012-02-05 16:08:53

+0

Splint還定義了_Transfer Error_'fresh-trans'爲:_「新分配的存儲傳輸到非唯一引用(內存泄漏)_」。 – 2012-02-05 16:19:39

相關問題