4 /* メモリを確保できない場合はエラーを出力して終了 */
5 void *malloc_chk(size_t size, char *tag)
9 if((p = malloc(size)) == NULL) {
10 fprintf(stderr, "%s: cannot allocate memory\n", tag);
13 return memset(p, 0, size);
17 /* メモリを確保できない場合はエラーを出力して終了 */
18 void *calloc_chk(size_t nmemb, size_t size, char *tag)
22 if((p = calloc(nmemb, size)) == NULL) {
23 fprintf(stderr, "%s: cannot allocate memory\n", tag);
29 /* malloc_chkを実行してメモリを確保してから、 */
31 char *strdup_chk(const char *s, char *tag)
36 t = malloc_chk(strlen(s) + 1, tag);
42 void free_chk(void *ptr, char *tag)