comparison src/debug.c @ 37:ddfb25318812 stable-0-5-8

more valgrind fixes
author carl
date Fri, 10 Aug 2007 08:06:13 -0700
parents 6fe121a971c9
children f6db1f060a95
comparison
equal deleted inserted replaced
36:6fe121a971c9 37:ddfb25318812
319 fseek(debug_fp, index_pos, SEEK_SET); 319 fseek(debug_fp, index_pos, SEEK_SET);
320 fwrite(index, index_size, 1, debug_fp); 320 fwrite(index, index_size, 1, debug_fp);
321 fseek(debug_fp, 0, SEEK_END); 321 fseek(debug_fp, 0, SEEK_END);
322 item_ptr = item_head = item_tail = NULL; 322 item_ptr = item_head = item_tail = NULL;
323 free(index); 323 free(index);
324 if (buf) free(buf); buf = NULL; 324 if (buf) free(buf);
325 } 325 }
326 326
327 327
328 void _debug_write_msg(struct _debug_item *item, char *fmt, va_list *ap, int size) { 328 void _debug_write_msg(struct _debug_item *item, char *fmt, va_list *ap, int size) {
329 struct _debug_file_rec_l lfile_rec; 329 struct _debug_file_rec_l lfile_rec;
330 struct _debug_file_rec_m mfile_rec; 330 struct _debug_file_rec_m mfile_rec;
331 unsigned char rec_type; 331 unsigned char rec_type;
332 int index_size = 3 * sizeof(int); 332 int index_size = 3 * sizeof(int);
333 int *index = malloc(index_size); 333 int index[3];
334 int index_pos, file_pos; 334 int index_pos, file_pos;
335 char zero='\0'; 335 char zero='\0';
336 unsigned int end; 336 unsigned int end;
337 if (!debug_fp) return; // no file 337 if (!debug_fp) return; // no file
338 index[0] = 1; //only one item in this index 338 index[0] = 1; //only one item in this index
379 fwrite(&rec_type, 1, sizeof(char), debug_fp); 379 fwrite(&rec_type, 1, sizeof(char), debug_fp);
380 mfile_rec.end = end; 380 mfile_rec.end = end;
381 fwrite(&mfile_rec, sizeof(mfile_rec), 1, debug_fp); 381 fwrite(&mfile_rec, sizeof(mfile_rec), 1, debug_fp);
382 } 382 }
383 fseek(debug_fp, 0, SEEK_END); 383 fseek(debug_fp, 0, SEEK_END);
384 // that should do it...
385 } 384 }
386 385
387 386
388 void _debug_write_hex(struct _debug_item *item, unsigned char *buf, int size, int col) { 387 void _debug_write_hex(struct _debug_item *item, unsigned char *buf, int size, int col) {
389 struct _debug_file_rec_l lfile_rec; 388 struct _debug_file_rec_l lfile_rec;
390 unsigned char rec_type; 389 unsigned char rec_type;
391 int index_size = 3 * sizeof(int); 390 int index_size = 3 * sizeof(int);
392 int index_pos, file_pos, *index; 391 int index_pos, file_pos, index[3];
393 char zero='\0'; 392 char zero='\0';
394 if (!debug_fp) return; // no file 393 if (!debug_fp) return; // no file
395 index = malloc(index_size);
396 index[0] = 1; // only one item in this index run 394 index[0] = 1; // only one item in this index run
397 index[1] = 0; // valgrind, avoid writing uninitialized data 395 index[1] = 0; // valgrind, avoid writing uninitialized data
398 index[2] = 0; // "" 396 index[2] = 0; // ""
399 index_pos = ftell(debug_fp); 397 index_pos = ftell(debug_fp);
400 fwrite(index, index_size, 1, debug_fp); 398 fwrite(index, index_size, 1, debug_fp);
432 void *mem = malloc(size); 430 void *mem = malloc(size);
433 if (!mem) { 431 if (!mem) {
434 fprintf(stderr, "xMalloc: Out Of memory [req: %ld]\n", (long)size); 432 fprintf(stderr, "xMalloc: Out Of memory [req: %ld]\n", (long)size);
435 exit(1); 433 exit(1);
436 } 434 }
437 memset(mem, 0, size); // valgrind, some email attachment does not initialize the entire buffer passed to base64 encode 435 //memset(mem, 0, size); // valgrind
438 return mem; 436 return mem;
439 } 437 }
440 438