[libcamera-devel,v2,1/4] cam: free allocated buffers when done capturing

Message ID 20190224171407.7856-2-niklas.soderlund@ragnatech.se
State Accepted
Commit 24cb5638533d19f77dd2f7f629f05eb07484ab97
Headers show
Series
  • cam: improve error paths
Related show

Commit Message

Niklas Söderlund Feb. 24, 2019, 5:14 p.m. UTC
The allocated buffers needs to be freed once the application is done
with them.

Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 src/cam/main.cpp | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

Patch

diff --git a/src/cam/main.cpp b/src/cam/main.cpp
index 9b67ab75a6a1663e..b034eb25429abeb3 100644
--- a/src/cam/main.cpp
+++ b/src/cam/main.cpp
@@ -163,7 +163,8 @@  static int capture()
 		Request *request = camera->createRequest();
 		if (!request) {
 			std::cerr << "Can't create request" << std::endl;
-			return -ENOMEM;
+			ret = -ENOMEM;
+			goto out;
 		}
 
 		std::map<Stream *, Buffer *> map;
@@ -171,13 +172,13 @@  static int capture()
 		ret = request->setBuffers(map);
 		if (ret < 0) {
 			std::cerr << "Can't set buffers for request" << std::endl;
-			return ret;
+			goto out;
 		}
 
 		ret = camera->queueRequest(request);
 		if (ret < 0) {
 			std::cerr << "Can't queue request" << std::endl;
-			return ret;
+			goto out;
 		}
 	}
 
@@ -187,6 +188,9 @@  static int capture()
 	ret = loop->exec();
 
 	camera->stop();
+out:
+	camera->freeBuffers();
+
 	return ret;
 }