Changeset 8b5690f in mainline for uspace/lib/c/generic/stats.c
- Timestamp:
- 2011-02-03T05:11:01Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- ba38f72c
- Parents:
- 22027b6e (diff), 86d7bfa (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/generic/stats.c
r22027b6e r8b5690f 36 36 #include <stats.h> 37 37 #include <sysinfo.h> 38 #include <assert.h>39 38 #include <errno.h> 40 39 #include <stdio.h> 41 40 #include <inttypes.h> 41 #include <malloc.h> 42 42 43 43 #define SYSINFO_STATS_MAX_PATH 64 … … 71 71 (stats_cpu_t *) sysinfo_get_data("system.cpus", &size); 72 72 73 assert((size % sizeof(stats_cpu_t)) == 0); 73 if ((size % sizeof(stats_cpu_t)) != 0) { 74 if (stats_cpus != NULL) 75 free(stats_cpus); 76 *count = 0; 77 return NULL; 78 } 74 79 75 80 *count = size / sizeof(stats_cpu_t); … … 91 96 (stats_physmem_t *) sysinfo_get_data("system.physmem", &size); 92 97 93 assert((size == sizeof(stats_physmem_t)) || (size == 0)); 98 if (size != sizeof(stats_physmem_t)) { 99 if (stats_physmem != NULL) 100 free(stats_physmem); 101 return NULL; 102 } 94 103 95 104 return stats_physmem; … … 111 120 (stats_task_t *) sysinfo_get_data("system.tasks", &size); 112 121 113 assert((size % sizeof(stats_task_t)) == 0); 122 if ((size % sizeof(stats_task_t)) != 0) { 123 if (stats_tasks != NULL) 124 free(stats_tasks); 125 *count = 0; 126 return NULL; 127 } 114 128 115 129 *count = size / sizeof(stats_task_t); … … 135 149 (stats_task_t *) sysinfo_get_data(name, &size); 136 150 137 assert((size == sizeof(stats_task_t)) || (size == 0)); 151 if (size != sizeof(stats_task_t)) { 152 if (stats_task != NULL) 153 free(stats_task); 154 return NULL; 155 } 138 156 139 157 return stats_task; … … 155 173 (stats_thread_t *) sysinfo_get_data("system.threads", &size); 156 174 157 assert((size % sizeof(stats_thread_t)) == 0); 175 if ((size % sizeof(stats_thread_t)) != 0) { 176 if (stats_threads != NULL) 177 free(stats_threads); 178 *count = 0; 179 return NULL; 180 } 158 181 159 182 *count = size / sizeof(stats_thread_t); … … 179 202 (stats_thread_t *) sysinfo_get_data(name, &size); 180 203 181 assert((size == sizeof(stats_thread_t)) || (size == 0)); 204 if (size != sizeof(stats_thread_t)) { 205 if (stats_thread != NULL) 206 free(stats_thread); 207 return NULL; 208 } 182 209 183 210 return stats_thread; … … 199 226 (stats_exc_t *) sysinfo_get_data("system.exceptions", &size); 200 227 201 assert((size % sizeof(stats_exc_t)) == 0); 228 if ((size % sizeof(stats_exc_t)) != 0) { 229 if (stats_exceptions != NULL) 230 free(stats_exceptions); 231 *count = 0; 232 return NULL; 233 } 202 234 203 235 *count = size / sizeof(stats_exc_t); … … 217 249 { 218 250 char name[SYSINFO_STATS_MAX_PATH]; 219 snprintf(name, SYSINFO_STATS_MAX_PATH, "system.exceptions s.%u", excn);251 snprintf(name, SYSINFO_STATS_MAX_PATH, "system.exceptions.%u", excn); 220 252 221 253 size_t size = 0; … … 223 255 (stats_exc_t *) sysinfo_get_data(name, &size); 224 256 225 assert((size == sizeof(stats_exc_t)) || (size == 0)); 257 if (size != sizeof(stats_exc_t)) { 258 if (stats_exception != NULL) 259 free(stats_exception); 260 return NULL; 261 } 226 262 227 263 return stats_exception; … … 243 279 (load_t *) sysinfo_get_data("system.load", &size); 244 280 245 assert((size % sizeof(load_t)) == 0); 281 if ((size % sizeof(load_t)) != 0) { 282 if (load != NULL) 283 free(load); 284 *count = 0; 285 return NULL; 286 } 246 287 247 288 *count = size / sizeof(load_t);
Note:
See TracChangeset
for help on using the changeset viewer.