Skip to content

Commit 6e6015c

Browse files
Antonio Ospitezarvox
authored andcommitted
examples: call freenect_shutdown() on exit
This is mostly useful when using tools like valgrind, which may report possibly lost memory even if the operating systems is going to get it back anyway on the actual process exit. Signed-off-by: Antonio Ospite <ospite@studenti.unina.it>
1 parent 071f51e commit 6e6015c

File tree

5 files changed

+25
-5
lines changed

5 files changed

+25
-5
lines changed

examples/glview.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -421,17 +421,21 @@ int main(int argc, char **argv)
421421
if (argc > 1)
422422
user_device_number = atoi(argv[1]);
423423

424-
if (nr_devices < 1)
424+
if (nr_devices < 1) {
425+
freenect_shutdown(f_ctx);
425426
return 1;
427+
}
426428

427429
if (freenect_open_device(f_ctx, &f_dev, user_device_number) < 0) {
428430
printf("Could not open device\n");
431+
freenect_shutdown(f_ctx);
429432
return 1;
430433
}
431434

432435
res = pthread_create(&freenect_thread, NULL, freenect_threadfunc, NULL);
433436
if (res) {
434437
printf("pthread_create failed\n");
438+
freenect_shutdown(f_ctx);
435439
return 1;
436440
}
437441

examples/hiview.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -445,17 +445,21 @@ int main(int argc, char **argv)
445445
if (argc > 1)
446446
user_device_number = atoi(argv[1]);
447447

448-
if (nr_devices < 1)
448+
if (nr_devices < 1) {
449+
freenect_shutdown(f_ctx);
449450
return 1;
451+
}
450452

451453
if (freenect_open_device(f_ctx, &f_dev, user_device_number) < 0) {
452454
printf("Could not open device\n");
455+
freenect_shutdown(f_ctx);
453456
return 1;
454457
}
455458

456459
res = pthread_create(&freenect_thread, NULL, freenect_threadfunc, NULL);
457460
if (res) {
458461
printf("pthread_create failed\n");
462+
freenect_shutdown(f_ctx);
459463
return 1;
460464
}
461465

examples/micview.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,12 +161,15 @@ int main(int argc, char** argv) {
161161

162162
int nr_devices = freenect_num_devices (f_ctx);
163163
printf ("Number of devices found: %d\n", nr_devices);
164-
if (nr_devices < 1)
164+
if (nr_devices < 1) {
165+
freenect_shutdown(f_ctx);
165166
return 1;
167+
}
166168

167169
int user_device_number = 0;
168170
if (freenect_open_device(f_ctx, &f_dev, user_device_number) < 0) {
169171
printf("Could not open device\n");
172+
freenect_shutdown(f_ctx);
170173
return 1;
171174
}
172175

@@ -188,6 +191,7 @@ int main(int argc, char** argv) {
188191
int res = pthread_create(&freenect_thread, NULL, freenect_threadfunc, NULL);
189192
if (res) {
190193
printf("pthread_create failed\n");
194+
freenect_shutdown(f_ctx);
191195
return 1;
192196
}
193197
printf("This is the libfreenect microphone waveform viewer. Press 'q' to quit or spacebar to pause/unpause the view.\n");

examples/regview.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,17 +363,21 @@ int main(int argc, char **argv)
363363
if (argc > 1)
364364
user_device_number = atoi(argv[1]);
365365

366-
if (nr_devices < 1)
366+
if (nr_devices < 1) {
367+
freenect_shutdown(f_ctx);
367368
return 1;
369+
}
368370

369371
if (freenect_open_device(f_ctx, &f_dev, user_device_number) < 0) {
370372
printf("Could not open device\n");
373+
freenect_shutdown(f_ctx);
371374
return 1;
372375
}
373376

374377
res = pthread_create(&freenect_thread, NULL, freenect_threadfunc, NULL);
375378
if (res) {
376379
printf("pthread_create failed\n");
380+
freenect_shutdown(f_ctx);
377381
return 1;
378382
}
379383

examples/wavrecord.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,15 @@ int main(int argc, char** argv) {
8080

8181
int nr_devices = freenect_num_devices (f_ctx);
8282
printf ("Number of devices found: %d\n", nr_devices);
83-
if (nr_devices < 1)
83+
if (nr_devices < 1) {
84+
freenect_shutdown(f_ctx);
8485
return 1;
86+
}
8587

8688
int user_device_number = 0;
8789
if (freenect_open_device(f_ctx, &f_dev, user_device_number) < 0) {
8890
printf("Could not open device\n");
91+
freenect_shutdown(f_ctx);
8992
return 1;
9093
}
9194

@@ -135,5 +138,6 @@ int main(int argc, char** argv) {
135138
fclose(state.logfiles[i]);
136139
}
137140

141+
freenect_shutdown(f_ctx);
138142
return 0;
139143
}

0 commit comments

Comments
 (0)