vmclear.c 1004 B

1234567891011121314151617181920212223242526272829303132
  1. /*************************************************************************
  2. * Copyright (c) 2011 AT&T Intellectual Property
  3. * All rights reserved. This program and the accompanying materials
  4. * are made available under the terms of the Eclipse Public License v1.0
  5. * which accompanies this distribution, and is available at
  6. * https://www.eclipse.org/legal/epl-v10.html
  7. *
  8. * Contributors: Details at https://graphviz.org
  9. *************************************************************************/
  10. #include <vmalloc/vmalloc.h>
  11. #include <stdlib.h>
  12. /** Clear out all allocated space.
  13. *
  14. * Note that this leaves the allocation region itself usable, but just frees all
  15. * previous allocations made within this region.
  16. *
  17. * @param vm Vmalloc to operate on
  18. */
  19. void vmclear(Vmalloc_t *vm) {
  20. // free all allocated pointers
  21. for (size_t i = 0; i < vm->size; ++i) {
  22. free(vm->allocated[i]);
  23. }
  24. // reset our metadata
  25. free(vm->allocated);
  26. vm->allocated = NULL;
  27. vm->size = vm->capacity = 0;
  28. }