Signed-off-by: Chris Lalancette <[email protected]>
---
src/classad_plugin/deltacloud_classad_plugin.cpp | 47 ++++++++++++----------
1 files changed, 26 insertions(+), 21 deletions(-)
diff --git a/src/classad_plugin/deltacloud_classad_plugin.cpp
b/src/classad_plugin/deltacloud_classad_plugin.cpp
index dc79cbb..dc3fb10 100644
--- a/src/classad_plugin/deltacloud_classad_plugin.cpp
+++ b/src/classad_plugin/deltacloud_classad_plugin.cpp
@@ -44,11 +44,11 @@ deltacloud_quota_check(const char *name, const ArgumentList
&arglist,
Value instance_key;
Value account_id;
FILE *fp;
- char msg[1024];
VALUE res;
bool val = false;
char *ruby_string;
std::stringstream method_args;
+ int rc;
result.SetBooleanValue(false);
@@ -91,26 +91,31 @@ deltacloud_quota_check(const char *name, const ArgumentList
&arglist,
method_args << "'" << DELTACLOUD_INSTALL_DIR << "/config/database.yml', '"
<< instance_key << "', " << account_id;
- asprintf(&ruby_string,
- "$: << '%s/classad_plugin'\n"
- "$: << '%s/app/models'\n"
- "logf = File.new('%s', 'a')\n"
- "logf.puts \"Loading ruby support file from %s/classad_plugin\"\n"
- "begin\n"
- " require 'classad_plugin.rb'\n"
- " ret = classad_plugin(logf, %s)\n"
- "rescue Exception => ex\n"
- " logf.puts \"Error running classad plugin: #{ex.message}\"\n"
- " logf.puts ex.backtrace\n"
- " ret = false\n"
- "end\n"
- "logf.close\n"
- "ret",
- DELTACLOUD_INSTALL_DIR,
- DELTACLOUD_INSTALL_DIR,
- LOGFILE,
- DELTACLOUD_INSTALL_DIR,
- method_args.str().c_str());
+ rc = asprintf(&ruby_string,
+ "$: << '%s/classad_plugin'\n"
+ "$: << '%s/app/models'\n"
+ "logf = File.new('%s', 'a')\n"
+ "logf.puts \"Loading ruby support file from
%s/classad_plugin\"\n"
+ "begin\n"
+ " require 'classad_plugin.rb'\n"
+ " ret = classad_plugin(logf, %s)\n"
+ "rescue Exception => ex\n"
+ " logf.puts \"Error running classad plugin:
#{ex.message}\"\n"
+ " logf.puts ex.backtrace\n"
+ " ret = false\n"
+ "end\n"
+ "logf.close\n"
+ "ret",
+ DELTACLOUD_INSTALL_DIR,
+ DELTACLOUD_INSTALL_DIR,
+ LOGFILE,
+ DELTACLOUD_INSTALL_DIR,
+ method_args.str().c_str());
+
+ if (rc < 0) {
+ fprintf(fp, "Failed to allocate memory for asprintf\n");
+ goto do_ret;
+ }
fprintf(fp, "ruby string is %s\n", ruby_string);
fflush(fp);
--
1.7.2.3
_______________________________________________
deltacloud-devel mailing list
[email protected]
https://fedorahosted.org/mailman/listinfo/deltacloud-devel