Changeset df3a1f4


Ignore:
Timestamp:
Feb 4, 2011, 3:49:44 PM (13 years ago)
Author:
David Benjamin <davidben@mit.edu>
Branches:
master, release-1.10, release-1.8, release-1.9
Children:
0290b2a
Parents:
9de316d1
git-author:
David Benjamin <davidben@mit.edu> (01/24/11 23:16:10)
git-committer:
David Benjamin <davidben@mit.edu> (02/04/11 15:49:44)
Message:
Replace realloc logic in owl_zephyr_getsubs with GString
File:
1 edited

Legend:

Unmodified
Added
Removed
  • zephyr.c

    rfc7481a rdf3a1f4  
    11271127#ifdef HAVE_LIBZEPHYR
    11281128  int ret, num, i, one;
    1129   int buffsize;
    11301129  ZSubscription_t sub;
    1131   char *out;
    1132   one=1;
     1130  GString *buf;
    11331131
    11341132  ret=ZRetrieveSubscriptions(0, &num);
     
    11391137  }
    11401138
    1141   buffsize = (num + 1) * 50;
    1142   out=owl_malloc(buffsize);
    1143   strcpy(out, "");
     1139  buf = g_string_new("");
    11441140  for (i=0; i<num; i++) {
     1141    one = 1;
    11451142    if ((ret = ZGetSubscriptions(&sub, &one)) != ZERR_NONE) {
    1146       owl_free(out);
    11471143      ZFlushSubscriptions();
    1148       out=owl_strdup("Error while getting subscriptions\n");
    1149       return(out);
     1144      g_string_free(buf, true);
     1145      return owl_strdup("Error while getting subscriptions\n");
    11501146    } else {
    1151       int tmpbufflen;
    1152       char *tmpbuff;
    1153       tmpbuff = owl_sprintf("<%s,%s,%s>\n%s", sub.zsub_class, sub.zsub_classinst, sub.zsub_recipient, out);
    1154       tmpbufflen = strlen(tmpbuff) + 1;
    1155       if (tmpbufflen > buffsize) {
    1156         char *out2;
    1157         buffsize = tmpbufflen * 2;
    1158         out2 = owl_realloc(out, buffsize);
    1159         if (out2 == NULL) {
    1160           owl_free(out);
    1161           owl_free(tmpbuff);
    1162           ZFlushSubscriptions();
    1163           out=owl_strdup("Realloc error while getting subscriptions\n");
    1164           return(out);   
    1165         }
    1166         out = out2;
    1167       }
    1168       strcpy(out, tmpbuff);
    1169       owl_free(tmpbuff);
     1147      /* g_string_append_printf would be backwards. */
     1148      char *tmp = owl_sprintf("<%s,%s,%s>\n",
     1149                              sub.zsub_class,
     1150                              sub.zsub_classinst,
     1151                              sub.zsub_recipient);
     1152      g_string_prepend(buf, tmp);
     1153      owl_free(tmp);
    11701154    }
    11711155  }
    11721156
    11731157  ZFlushSubscriptions();
    1174   return(out);
     1158  return g_string_free(buf, false);
    11751159#else
    11761160  return(owl_strdup("Zephyr not available"));
Note: See TracChangeset for help on using the changeset viewer.