commit-gnuradio
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Commit-gnuradio] [gnuradio] 02/02: runtime: do not return buffer create


From: git
Subject: [Commit-gnuradio] [gnuradio] 02/02: runtime: do not return buffer created on stact #722
Date: Sun, 22 Mar 2015 15:59:43 +0000 (UTC)

This is an automated email from the git hooks/post-receive script.

jcorgan pushed a commit to branch maint
in repository gnuradio.

commit f042e44d18c481e7e2ca37895afbd6ecf42061a3
Author: Jiří Pinkava <address@hidden>
Date:   Thu Mar 12 11:23:16 2015 +0100

    runtime: do not return buffer created on stact #722
---
 gnuradio-runtime/lib/vmcircbuf.cc       |  5 ++---
 gnuradio-runtime/lib/vmcircbuf_prefs.cc | 16 +++++++---------
 gnuradio-runtime/lib/vmcircbuf_prefs.h  |  2 +-
 3 files changed, 10 insertions(+), 13 deletions(-)

diff --git a/gnuradio-runtime/lib/vmcircbuf.cc 
b/gnuradio-runtime/lib/vmcircbuf.cc
index d17ed72..05f08ce 100644
--- a/gnuradio-runtime/lib/vmcircbuf.cc
+++ b/gnuradio-runtime/lib/vmcircbuf.cc
@@ -68,9 +68,8 @@ namespace gr {
 
     std::vector<gr::vmcircbuf_factory *> all = all_factories ();
 
-    const char *name = gr::vmcircbuf_prefs::get(FACTORY_PREF_KEY);
-
-    if(name) {
+    char name[1024];
+    if (gr::vmcircbuf_prefs::get(FACTORY_PREF_KEY, name, sizeof(name)) >= 0) {
       for(unsigned int i = 0; i < all.size (); i++) {
         if(strncmp(name, all[i]->name(), strlen(all[i]->name())) == 0) {
           s_default_factory = all[i];
diff --git a/gnuradio-runtime/lib/vmcircbuf_prefs.cc 
b/gnuradio-runtime/lib/vmcircbuf_prefs.cc
index 258605c..a786b8a 100644
--- a/gnuradio-runtime/lib/vmcircbuf_prefs.cc
+++ b/gnuradio-runtime/lib/vmcircbuf_prefs.cc
@@ -65,11 +65,9 @@ namespace gr {
       fs::create_directory(path);
   }
 
-  const char *
-  vmcircbuf_prefs::get(const char *key)
+  int
+  vmcircbuf_prefs::get(const char *key, char *value, int value_size)
   {
-    static char buf[1024];
-
     gr::thread::scoped_lock guard(s_vm_mutex);
 
     FILE *fp = fopen(pathname (key), "r");
@@ -78,17 +76,17 @@ namespace gr {
       return 0;
     }
 
-    memset(buf, 0, sizeof (buf));
-    size_t ret = fread(buf, 1, sizeof(buf) - 1, fp);
-    if(ret == 0) {
+    const size_t ret = fread(value, 1, value_size - 1, fp);
+    value[ret] = '\0';
+    if(ret == 0 && !feof(fp)) {
       if(ferror(fp) != 0) {
         perror(pathname (key));
         fclose(fp);
-        return 0;
+        return -1;
       }
     }
     fclose(fp);
-    return buf;
+    return ret;
   }
 
   void
diff --git a/gnuradio-runtime/lib/vmcircbuf_prefs.h 
b/gnuradio-runtime/lib/vmcircbuf_prefs.h
index 709b8ff..ec7b699 100644
--- a/gnuradio-runtime/lib/vmcircbuf_prefs.h
+++ b/gnuradio-runtime/lib/vmcircbuf_prefs.h
@@ -30,7 +30,7 @@ namespace gr {
   class GR_RUNTIME_API vmcircbuf_prefs
   {
   public:
-    static const char *get(const char *key);
+    static int get(const char *key, char *value, int value_size);
     static void set(const char *key, const char *value);
   };
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]