Browse Source

- release the db_res structure if execution of the command fails

Jan Janak 18 years ago
parent
commit
a272048363
1 changed files with 10 additions and 3 deletions
  1. 10 3
      db/db_cmd.c

+ 10 - 3
db/db_cmd.c

@@ -187,16 +187,23 @@ void db_cmd_free(db_cmd_t* cmd)
 int db_exec(db_res_t** res, db_cmd_t* cmd)
 {
 	db_res_t* r = NULL;
-
+	int ret;
+	
 	if (res) {
 		r = db_res(cmd);
 		if (r == NULL) return -1;
-		if (res) *res = r;
 	}
 
 	/* FIXME */
 	db_payload_idx = 0;
-	return cmd->exec[0](r, cmd);
+	ret = cmd->exec[0](r, cmd);
+	if (ret < 0) {
+		if (r) db_res_free(r);
+		return ret;
+	}
+
+	if (res) *res = r;
+	return ret;
 }
 
 /** @} */